dongsheng6056 2008-12-11 11:23
浏览 30
已采纳

PHP文件上传麻烦

I'm having an extremely weird problem with a PHP script of mine.

I'm uploading a couple of files and having PHP put them all in one folder. I've have trouble with random files being sent and random ones not being sent. So I debugged it and I got a very weird result from the $_FILES[] array.

I tried it with 3 files.

$_FILES["addFile"]["name"] Holds the names of the 3 files.

You'd expect $_FILES["addFile"]["tmp_name"] to hold the 3 temporary names that PHP uses to copy the files, but it doesn't. It holds just one name. The other 2 are empty strings, which generate an error whilst uploading(which I supress from being displayed)

This is very odd. I've tried mulitple situations and it just keeps on happening. This must be something in my settings or perhaps even my code.

Here's my code:

$i = 0;
  if (!empty($_FILES['addFile'])) {
    foreach($_FILES['addFile'] as $addFile) {
      $fileToCopy = $_FILES["addFile"]["tmp_name"][$i];
      $fileName   = $_FILES["addFile"]["name"][$i];
      $i++;
      if(!empty($fileToCopy)){
       $copyTo = $baseDir."/".$fileName;
       @copy($fileToCopy, $copyTo) or die("cannot copy ".$fileToCopy." to ".$copyTo);
      }
     }
          exit(0);
   }

Since the tmp_name is empty, the if-value will be false so it's gonna skip the die() function.

Does anybody know what might be causing this?

further info: I'm using Windows XP, running WAMP server. Never had this problem before and I can acces all maps from which I've tried to upload. Security settings of windows can't be the issue I think.

  • 写回答

3条回答 默认 最新

  • dpz1983 2008-12-11 11:28
    关注

    Relevent, but probably not going to help: but move_uploaded_file is a (slightly) better way to handle uploaded files than copy.

    Are any of the files large? PHP has limits on the filesize and the time it can take to upload them ...

    Better to send you here than attempt to write up what it says:

    http://uk3.php.net/manual/en/features.file-upload.common-pitfalls.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料