douzhi3454 2017-09-05 12:17
浏览 227
已采纳

上传文件时,文件大小统计失败

I'm facing strange problem right now - "filesize(): stat failed for C:\xampp\tmp\php7A38.tmp" exception. The problem occurs when I'm uploading files in my application built with PHP (Laravel).

Before I'm uploading the files onto the server I'm checking size of files like this (this works very well):

for ($i = 0; $i < $filesLength; $i++) {
   if(filesize($request['files'][$i]) < 1572865) {
      $file = $request['files'][$i];
      $filename = $imageNumber.'.'.$request['files'][$i]->extension();
      $file = $file->move(public_path().'/app/newsimages/'.$element->id.'/', $filename);
   }
}

If I do it like that everything works very well. But the problem is that I have to put this loop in another loop, like this:

foreach($somelement as $element) {
  for ($i = 0; $i < $filesLength; $i++) {
    if(filesize($request['files'][$i]) < 1572865) {
      $file = $request['files'][$i];
      $filename = $imageNumber.'.'.$request['files'][$i]->extension();
      $file = $file->move(public_path().'/app/newsimages/'.$element->id.'/', $filename);
    }
  }
}

In addition to that it crashes at the second loop of the foreach loop.

Maybe you have some idea what's wrong in here?

  • 写回答

1条回答 默认 最新

  • dpikoto468637 2017-09-05 13:51
    关注

    I think this is obvious, in inner loop you move the file, so when you go to next iteration of outer loop file is not there, so for example if you once move the file:

    $request['files'][0]
    

    it's not possible to execute:

    filesize($request['files'][0])
    

    because this file was moved - it doesn't exist any more.

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

报告相同问题?

悬赏问题

  • ¥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,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题