PHP Classes

PHP Check Folder for New Files: Watch folder and send email when new files appear

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 121 All time: 9,492 This week: 146Up
Version License PHP version Categories
dirtracker 1.0.0MIT/X Consortium ...5PHP 5, System information, Files and ...
Description 

Author

This package can be used to watch a folder and send email when new files appear.

It can take the path of a given directory and checks the time of the last change of all files in the directory to get the list of all files that were changed since the last time this checking procedure was performed.

The class sends an email message for each of the files that were added or changed in the directory.

It stores in a control file the time of when each check was performed, so next time the check is done again it can compare that time with the time of last change done on each of the files present in the directory.

Picture of Dawood Ikhlaq
  Performance   Level  
Name: Dawood Ikhlaq <contact>
Classes: 8 packages by
Country: Italy Italy
Age: 30
All time rank: 194576 in Italy Italy
Week rank: 180 Up7 in Italy Italy Up
Innovation award
Innovation award
Nominee: 4x

Example

<?php
/**
 * Created by PhpStorm.
 * User: dawood.ikhlaq
 * Date: 02/04/2019
 * Time: 15:29
 */



include 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();


if(
$argc<2)
{
    echo
"Dir path is missing".PHP_EOL;
    echo
"Example {$argv[0]} /home/dir".PHP_EOL;
    die;
}

$directoryToTrack = realpath($argv[1]);

if(!
is_dir($directoryToTrack))
{
    echo
"directory doesn't exist".PHP_EOL;
    die;
}
$tracker = new \DirTrack\DirTrack($directoryToTrack);


while(
1)
{
    try{
       
$tracker->work();
    }catch (
Exception $exception)
    {
        echo
'Following error occured'.PHP_EOL;
        echo
$exception->getMessage().PHP_EOL;
    }
   
sleep(60*env('SLEEP_AFTER_QUERY',5));
}


Details

DirTracker

Simple PHP Package To Track The Directory For New Files and If New File Has Been Detected It Sends Email To Admin

Installation

git clone https://github.com/daudmalik06/DirTracker
cd DirTracker
composer install
cp .env.example .env
set SMTP credentials in .env file and other variables

Usage

php track.php /path/to/dir


  Files folder image Files (9)  
File Role Description
Files folder imagesrc (3 files)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file last_timestamp Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file track.php Example Example script

  Files folder image Files (9)  /  src  
File Role Description
  Plain text file DirTrack.php Class Class source
  Accessible without login Plain text file helper.php Aux. Auxiliary script
  Accessible without login Plain text file last_timestamp Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:121
This week:0
All time:9,492
This week:146Up