0

my script is that. It compare files in a folder to files in database. If one file in my folder is not in my database, it inserts it. Now I would like to add a functionalit to compare the modified date of the file. If it has been modified, I insert it, and if not, just do nothing.

I tried to do something, but not sure how to make it.

bellow my script

$bdd = new PDO('mysql:host=localhost;dbname=check', 'root', 'root');

$dirname = './check/';
$dir = scandir($dirname);

$fichiers_bdd = $bdd->query("SELECT filename, modifiedDate1 FROM file");
$fichiers_bdd = $fichiers_bdd->fetchAll(PDO::FETCH_COLUMN); 


$params = array();
$i = 0;
foreach($dir as $file) {
    if($file != '.' && $file != '..' && !is_dir($dirname.$file) && !in_array($file, $fichiers_bdd))
    {

        if($i == 0){
            $req="INSERT INTO file (filename, modifiedDate1) VALUES";
            $i++;
        }else $req .=", ";
    $req .= "(?, '$modifiedDate1')";
    $params[] = $file;
    var_dump($req);
    }
}


if(!empty($params)){
    $stmt = $bdd->prepare($req);
    $stmt->execute($params);
}else echo "all files are already in database.";
maevy
  • 363
  • 1
  • 3
  • 12
  • You should use `filesize()` and `filemtime()` I've got a script which checks file that have been modified between two points of time. Maybe you can use it in some way. – Rimble Dec 29 '14 at 14:21
  • http://pastebin.com/PbS1UtaU – Rimble Dec 29 '14 at 14:23
  • I found a script from filemtime(), I think its the same than you, it helps me thats good – maevy Dec 29 '14 at 14:27
  • yes its kind of pastebin but shorter, thank you i'm going to take a look of that. – maevy Dec 29 '14 at 14:28
  • If you want to know if the contents of the file is different, you may also want to take a look at http://php.net/sha1_file (or something similar). – Jory Geerts Dec 29 '14 at 15:43

0 Answers0