【问题标题】:PHP File Upload - Can't Upload / DebugPHP 文件上传 - 无法上传/调试
【发布时间】:2012-04-26 00:13:51
【问题描述】:

我正在尝试上传文件但我不工作:

有用信息:运行 IIS Express(使用 PHP 5.3)- Windows 7 Professional 32 位

代码:

move_uploaded_file($_FILES["imagem"]["name"], "/images/" . $_FILES["imagem"]["name"]) 或死 ("Error:".print_r($_FILES) );

它打印: Array ( [imagem] => Array ( [name] => Chrysanthemum.jpg [type] => image/jpeg [tmp_name] => C:\Windows\Temp\ php3D85.tmp [错误] => 0 [大小] => 879394 ) )

我确定路径是正确的,我也做了 chmod() 来设置权限,但仍然没有上传。
有什么建议吗?

【问题讨论】:

  • 第一个参数应该是$_FILES['imagem']['tmp_name']并尝试使用./images/

标签: php windows file-upload iis-express


【解决方案1】:

您的目标路径应以指向图像目录的正确路径开头(dirname(__FILE__) 可以提供帮助)。就目前而言,"/images/" . $_FILES["imagem"]["name"] 意味着它将尝试写入可能不存在的C:/images/(假设脚本位于C: 驱动器中)。

【讨论】:

    【解决方案2】:

    由于它位于数组内部,因此您需要在 foreach 循环中执行移动上传文件功能。

    foreach($_FILES['imagem'] as $f){
    move_uploaded_file($f['tmp_name'], "/images/" . $f["name"]);
    }
    

    您可能想尝试使用我的课程: http://code.google.com/p/daves-upload-class/source/browse/upload_class.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-09
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-17
      • 2016-06-07
      • 2016-02-19
      相关资源
      最近更新 更多