Frage

I'm calling the following:

while ( (!file_exists('./download/ah141090676723_100.jpg')) || (filesize('./download/ah141090676723_100.jpg') == '1359') ) { code that retrieves a remote file and writes it to '/ah141090676723_100.jpg'  }

... and getting a "filesize(): stat failed for ./download/ah141090676723_100.jpg" error.

The problem I'm trying to solve is that the remote server is flaky, and sometimes returns a garbage response (which is always 1359 bytes long). So, I want to check to see if either A) the file doesn't exist (first run through), or B) the file equals garbage (1359); if either is true, attempt to grab and write the file. Rinse and repeat until we get something that's not garbage.

The code actually seems to be working -- the file is retrieved and written, and I haven't had any garbage responses get through this loop -- but the error mystifies me. I thought it might be that on the first run-through, the file doesn't exist, so filesize is throwing this error. But the "||" operator should be preventing that second evaluation on the first run-through... right?

I should mention that I'm calling "clearstatcache();" inside the loop, after the retrieval/write.

Any help appreciated!

Scott

War es hilfreich?

Lösung

Change to

while ( file_exists('./download/ah141090676723_100.jpg') && filesize('./download/ah141090676723_100.jpg') == 1359) 

as file_exists is always required. filesize() returns "stat failed" when a file does not exist or is not readable.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top