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.

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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站