PHP文件上传麻烦 [英] PHP file uploading trouble

查看:66
本文介绍了PHP文件上传麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP脚本遇到一个非常奇怪的问题.

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

我正在上传几个文件,并用PHP将它们全部放在一个文件夹中. 我在发送随机文件和不发送随机文件时遇到麻烦.所以我调试了它,并从$ _FILES []数组中得到了一个非常奇怪的结果.

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.

我尝试了3个文件.

$_FILES["addFile"]["name"]保存3个文件的名称.

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

您希望$_FILES["addFile"]["tmp_name"]保留PHP用于复制文件的3个临时名称,但事实并非如此.它只有一个名字.其他2个是空字符串,在上传时会产生错误(我禁止显示)

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.

这是我的代码:

$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);
   }

由于tmp_name为空,因此if值将为false,因此它将跳过die()函数.

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?

更多信息:我使用的是运行WAMP服务器的Windows XP.以前从未遇到过此问题,我可以访问尝试从中上传的所有地图.我认为Windows的安全设置不是问题.

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.

推荐答案

事件,但可能无济于事:但是move_uploaded_file是一种处理上传文件的方法(略),胜过复制.

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

任何文件大吗? PHP对文件大小及其上载时间有限制...

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

这篇关于PHP文件上传麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆