Jump to content

save file names in an array and then compare.


denoteone

Recommended Posts

i want to get the names and sizes of files in a specific directory and the save them in and array and then 5 seconds later do it again and compare the two arrays. if they do not match exactly stop the script. This is what i have so far.... If anyone has a better way let me know.

 

$dir = "upload/new/";
$dh = opendir($dir);

while (($file = readdir($dh)) !== false) {
$images["file". $i  => $file, "file_size". $i  => filesize($file) ];
}

//Somehow wait 5 seconds and then run the while loop again 


while (($file = readdir($dh)) !== false) {
$images_new["file". $i  => $file, "file_size". $i  => filesize($file) ];
}

closedir($dh);

//now compare the two

If ($images != $images_new){

do this
}else{
echo "the arrays are the same";

}

 

Any ideas would be great!

the 5 second  wait is put in to  make sure that there are no files currently uploading to the directory.  So when the script is started I get the files and file sizes and put that into array #1 then wait 5 seconds and and get the names and sized again in a new array #2.

 

I then compare the two arrays and if they are not the same that means the file sizes has changed so an upload is happening.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.