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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
<?php /* * Pen Drive Content Copier * * @Author Abu Ashraf Masnun * @Email masnun@gmail.com * @URL https://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); } } ?> |