Nothing much to say. I am writing a PHP program that is intended to monitor for the availability of a directory and copy all data of that directory into another directory. It still needs huge improvements, testing and bug fixing. It was really fun coding it!
Feel free to play with the codes and drop me a few lines if you have something to say !
Here’s the source code:
<?php /* * Pen Drive Content Copier * * @Author Abu Ashraf Masnun * @Email masnun@gmail.com * @URL http://masnun.com * * @Description This script monitors for the availability of the * $source directory from time to time and copies all data into the * $target directory. * * //TODO Needs further improvements. Still in test phase. :( * */ $source = "/media/MASNUN"; // Source Directory -- Variable on Linux :-( $target = "/home/masnun/copies"; // Target Directory $sep = "/" ; // Directory Seperator while(true) { scanMedia(); } function scanMedia() { global $source, $target, $sep; if(is_dir($source)) { if(!file_exists($source.$sep."m17l40")) { full_copy( $source, $target ); file_put_contents($source.$sep."m17l40","bWFzbnVuICYgbGFib255"); } } } function full_copy( $source, $target ) { global $sep; if ( is_dir( $source ) ) { @mkdir( $target ); $d = dir( $source ); while ( FALSE !== ( $entry = $d->read() ) ) { if ( $entry == '.' || $entry == '..' ) { continue; } $Entry = $source . $sep . $entry; if ( is_dir( $Entry ) ) { full_copy( $Entry, $target . $sep . $entry ); continue; } copy( $Entry, $target . $sep . $entry ); } $d->close(); }else { copy( $source, $target ); } } if(!function_exists("file_put_contents")) { function file_put_contents($source,$data) { $fh = fopen($source,"w"); return fwrite($fh,$data); } } ?>
Well i am just too naive to use the program.
However, enlighten me informing the way to make it useful.
Cheers !
I think this would be better (and shorter) as a bash script but anyway, I’d suggest using sleep() in your while loop so it isn’t constantly polling.
Interesting idea, though!
Pingback: Tweets that mention Pen Drive Content Copier with PHP: The Source Code | maSnun.com -- Topsy.com