douzhi3454 2017-09-05 04: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 05: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 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验
  • ¥20 DNS服务器所在的国家不同与你的IP地址所在国家
  • ¥15 查询优化:A表100000行,B表2000 行,内存页大小只有20页,运行时3页,设计两个表等值连接的最简单的算法
  • ¥15 led数码显示控制(标签-流程图)
  • ¥20 为什么在复位后出现错误帧
  • ¥15 结果有了,想问一下这个具体怎么输入
  • ¥15 怎么修改鸿蒙app的UI及功能设计
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部