PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 120 This week: 1All time: 9,484 This week: 571Up
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: 29
All time rank: 194776 in Italy Italy
Week rank: 103 Up4 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  
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  /  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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:120
This week:1
All time:9,484
This week:571Up