1

我有一个在本地安装(PHP4/MySQL)中设计的应用程序,它运行良好。自从我将它移到实时安装(PHP5/MySQL)以来,我除了问题什么都没有!我修复了所有全局变量问题(让我学习 PDO,所以这不是一件坏事!)没有打开全局变量,所以我唯一的问题是文件上传。我尝试了 $_file 的 isset 测试,看起来变量从未设置过?有任何想法吗?

这是表单数据:

     <form enctype="multipart/form-data" method="post" action="script_add_product.php" >   

     <input class="cp_forms_upload" type="file" name="full_image" />

     <input class="cp_formsButton" type="submit" name="submit_button" value="Add Product" /></form>

这是PHP:

    $full_image_url = $_FILES["full_image"]["name"];     

    if ((($_FILES["full_image"]["type"] == "image/gif")
    || ($_FILES["full_image"]["type"] == "image/jpeg")
    || ($_FILES["full_image"]["type"] == "image/pjpeg")
    || ($_FILES["full_image"]["type"] == "image/png"))
    && ($_FILES["full_image"]["size"] < 400000))
      {
     if ($_FILES["full_image"]["error"] > 0)
      {
       echo "Return Code: " . $_FILES["full_image"]["error"] . "<br />";
       }
     else
       {
      echo "Upload: " . $_FILES["full_image"]["name"] . "<br />";
      echo "Type: " . $_FILES["full_image"]["type"] . "<br />";
      echo "Size: " . ($_FILES["full_image"]["size"] / 1024) . " Kb<br />";
      echo "Temp file: " . $_FILES["full_image"]["tmp_name"] . "<br />"; 

      if (file_exists("../Uploads/" . $_FILES["full_image"]["name"]))
       {
         echo $_FILES["full_image"]["name"] . " already exists. ";
        } 
      else 
         {
         move_uploaded_file($_FILES["full_image"]["tmp_name"],
         "../Uploads/" . $_FILES["full_image"]["name"]);
         echo "Stored in: " . "../Uploads/" . $_FILES["full_image"]["name"];
     echo "<br /><br /><br />" . $full_image_url;
         }
       }

      }

      else
      {
     echo "Invalid file";
       }

谢谢各位:)

4

3 回答 3

0

您能否检查一下您的php.inifor iffile_uploads是否设置为On.

; Whether to allow HTTP file uploads.
; http://ph .net/file-uplollow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
于 2012-07-28T19:59:53.387 回答
0

php.ini配置。

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = "...../tmp"

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 128M

它也可能有用memory_limitmax_execution_timephp.ini. 更多:处理文件上传 -> 常见陷阱

确保该文件夹"../Uploads/"存在并且有权在 apache/nginx 工作(www_data或类似)下为用户写入

于 2012-07-28T20:36:47.523 回答
-1

这可能是问题吗?本节中的附加 '(' 括号:

if (($_FILES["full_image"]["type"] == "image/gif")
    || ($_FILES["full_image"]["type"] == "image/jpeg")
    || ($_FILES["full_image"]["type"] == "image/pjpeg")
    || ($_FILES["full_image"]["type"] == "image/png"))
    && ($_FILES["full_image"]["size"] < 400000))
于 2012-07-28T23:01:11.883 回答