使用php上传文件时出错

时间:2015-01-11 19:37:35

标签: php

好的,过去2天我使用谷歌并没有弄清楚我的代码有什么问题。首先,似乎我使用了错误的路径,但官方的" Hilfe中心" (比如帮助中心左右)1和1表示这必须是正确的路径" e:\ Kunden \ Homepages \ 11 \ d12345678 \ www \ UploadTest" (显然你必须适应你的路径,我通过phpinfo()) 所以我使用以下代码:

<form action=\"upload.php\" method=\"post\" enctype=\"multipart/form-data\"> 
                <input type=\"file\" name=\"datei\"><br>
                <input style=\"position:absolute;left:5px\" type=\"submit\" value=\"Hochladen\"> 
                </form>

在您上传文件的网站上

$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
  $upload_path = "e:\\Kunden\\Homepages\\11\\d12345678\\www\\UploadTest";


   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).


   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.'); // if we upload large file then we get error.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.'); // if we have no enough permission then got error.

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)){
                    // if everything is fine then we upload file and go to somewhere else
         header ('location: whereeveryouwantogo.php');
     } else {
         echo 'There was an error during the file upload.  Please try again.';
    }

在运行php脚本的站点上(upload.php)。我在这里获得了另一个线程的代码,并希望将其用于故障排除。后来我回到了我自己的代码。

我现在处于最后一个错误:

&#39;文件上传期间出错。请再试一次。&#39;;

我只想上传稍后在新闻网站上使用的.txt文件。对于任何提前帮助的Thx!

1 个答案:

答案 0 :(得分:0)

我认为问题是输入的名称或文件变量的名称。 $文件= $ _ FILES [&#39; datei&#39;] [&#39; tmp_name的值&#39;];