douye2110 2013-10-15 00:14
浏览 3588
已采纳

php filesize返回stat失败错误

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

  • 写回答

1条回答 默认 最新

  • douqian1517 2016-01-12 20:47
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?