Forum Moderators: coopster

Message Too Old, No Replies

directory iterator php ignore partially loaded file

         

babushka

5:58 pm on May 24, 2008 (gmt 0)

10+ Year Member



Hello, Is there anyone way to ignore paritally uploaded files when using the directory iterator? I am looking for the most current file that has been completely uploaded. I do something like what's below and tried adding looking for files bigger than 9k, but I still run into the problem of selecting an image that is not fully loaded:

//get files timestamp and compare
$dirProc=new DirectoryIterator('pics/');
foreach($dirProc as $dirContent){
if($dirContent->isFile()){
//compare curent file's timestamp to that of stored timestamp. If later, then store it in the vars.
if( $dirContent->getMTime() > $latestdatetime && $dirContent->getSize() > (9 * 1024)) {
$latestdatetime = $dirContent->getMTime();
$latestfilename = $dirContent->getFilename();
}

}
}

jatar_k

2:57 pm on May 26, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't think there is necessarily any way to do that

a thought might be not to do the two processes in the same dir, upload to one and then copy over to the one where you grab the most recent

coopster

6:27 pm on May 26, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Exactly. The file will be deleted from the temporary upload directory at the end of the request if it has not been moved away or renamed. Separating the directories is the easiest solution.

babushka

3:06 am on May 27, 2008 (gmt 0)

10+ Year Member



ok, but I don't know when the files are uploaded. It is an auto ftp of images from a cam. The cam auto uploades every 10 seconds or so. Each time someone accesses the page, I 'iterate' through the directory to find the latest pic and send that to their browser. Sometimes I end up with a 'blank' image because the latest image hasn't loaded yet. The ftp upload is coming through a dsl connection and isn't the fastest. Although, it happens very infrequently, it still bugs me - me being anal retentive and all. lol

I have change the code to make sure the filesize is bigger than the lowest filesize I think it will upload and that helps. But I was wondering if there was a better solution.

Thanks

jatar_k

12:04 pm on May 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



another idea would be to always show the second last one