denoteone Posted April 27, 2010 Share Posted April 27, 2010 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! Link to comment https://forums.phpfreaks.com/topic/199964-save-file-names-in-an-array-and-then-compare/ Share on other sites More sharing options...
litebearer Posted April 27, 2010 Share Posted April 27, 2010 might also look at... http://php.net/manual/en/function.array-diff.php Link to comment https://forums.phpfreaks.com/topic/199964-save-file-names-in-an-array-and-then-compare/#findComment-1049536 Share on other sites More sharing options...
denoteone Posted April 27, 2010 Author Share Posted April 27, 2010 Ok i have the comparing of the array's working. But how can I increment so that the script continues after 5 seconds? Link to comment https://forums.phpfreaks.com/topic/199964-save-file-names-in-an-array-and-then-compare/#findComment-1049559 Share on other sites More sharing options...
litebearer Posted April 27, 2010 Share Posted April 27, 2010 Probably a better way, but... put it in a loop and use http://www.w3schools.com/php/func_misc_sleep.asp a lot depends on why you need to check so frequently Link to comment https://forums.phpfreaks.com/topic/199964-save-file-names-in-an-array-and-then-compare/#findComment-1049564 Share on other sites More sharing options...
denoteone Posted April 27, 2010 Author Share Posted April 27, 2010 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. Link to comment https://forums.phpfreaks.com/topic/199964-save-file-names-in-an-array-and-then-compare/#findComment-1049566 Share on other sites More sharing options...
denoteone Posted April 27, 2010 Author Share Posted April 27, 2010 Thanks litebearer! Link to comment https://forums.phpfreaks.com/topic/199964-save-file-names-in-an-array-and-then-compare/#findComment-1049580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.