简体   繁体   English

PHP上传文件问题

[英]PHP Uploading Files issue

Updated! 更新!

I have never had a problem with this before, i'm on a local server and UAC is turned off as well. 我以前从未遇到过这个问题,我在本地服务器上,并且UAC也已关闭。

Here is my form, well, a dumbed down version of the form as there is a lot of text in there: 这是我的表单,是表单的精简版,因为其中有很多文本:

<form id="setup" name="setup" action="php/process_setup.php" method="post" enctype="multipart/form-data">
   <input type="text" name="cname" id="cname" value="" />
   <input type="text" name="splash" id="splash" />
   <input type="file" name="file"/>
   <input type="text" name="email" id="email" />
   <input type="password" name="password" id="password" />
   <input type="password" name="cpassword" id="cpassword" />
   <input type="submit" value="Submit" name="submit_setup" />
</form>

Here is the PHP im trying: 这是PHP我正在尝试:

if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }

And here is the result: 结果如下:

Notice: Undefined index: file in C:\\xampp\\htdocs\\ppa\\php\\process_setup.php on line 10 注意:未定义的索引:第10行的C:\\ xampp \\ htdocs \\ ppa \\ php \\ process_setup.php中的文件

Notice: Undefined index: file in C:\\xampp\\htdocs\\ppa\\php\\process_setup.php on line 16 Upload: 注意:未定义的索引:第16行的C:\\ xampp \\ htdocs \\ ppa \\ php \\ process_setup.php中的文件上传:

Notice: Undefined index: file in C:\\xampp\\htdocs\\ppa\\php\\process_setup.php on line 17 Type: 注意:未定义的索引:第17行的C:\\ xampp \\ htdocs \\ ppa \\ php \\ process_setup.php中的文件类型:

Notice: Undefined index: file in C:\\xampp\\htdocs\\ppa\\php\\process_setup.php on line 18 Size: 0 kB 注意:未定义的索引:第18行的C:\\ xampp \\ htdocs \\ ppa \\ php \\ process_setup.php中的文件大小:0 kB

Notice: Undefined index: file in C:\\xampp\\htdocs\\ppa\\php\\process_setup.php on line 19 Stored in: 注意:未定义的索引:第19行的C:\\ xampp \\ htdocs \\ ppa \\ php \\ process_setup.php中的文件存储在:

Edit 2 编辑2

Just did a test to see if PHP has write permission, here is the code: 只是做了一个测试,看看PHP是否具有写权限,下面是代码:

echo copy("1383778885275.jpg", "C:/xampp/tmp/1383778885275.jpg");

And the result was: 结果是:

1 1个

And the image IS in the tmp directory.. 映像位于tmp目录中。

I am doing it in on a simple way , try having this: 我正在以一种简单的方式来做,尝试这样做:

if(!empty($_POST) && !empty($_FILES["file"]["name"]) ){ //check the following post values if not empty
    $name = $_FILES["file"]["name"];
    $temp = $_FILES["file"]["tmp_name"];
    $location= "../images/";
    if(move_uploaded_file($temp, $location.$name)) {
        echo "Uploaded!!!";
    } else {
        echo "Error:";
    }
} else {
    echo "Please choose a file to upload";
}

You probably need to change !empty($_FILES["file"]["tmp_name"] to: 您可能需要将!empty($_FILES["file"]["tmp_name"]更改为:

isset($_FILES["file"]["tmp_name"]

and if(move_uploaded_file($temp, $location.$name)) { to: if(move_uploaded_file($temp, $location.$name)) {到:

if(move_uploaded_file($temp, $location.basename($name))) {

Emphasis on basename() . 强调basename()

According to your notice information ,the $_FILES is probably empty.You can check the following issues: 根据您的通知信息, $_FILES _ FILES可能为空。您可以检查以下问题:

1.Make sure your directory has permissions for the tmp and upload directories.
2.Make sure the value of `file_uploads` option in `php.ini` is `On`

Thanks for all the help guys. 感谢所有帮助人员。 It seems that there was an issue in some of the code I didn't include.. :/ 似乎我未包含的某些代码存在问题..:/

Basically: 基本上:

<form id="setup" name="setup" action="php/process_setup.php" method="post" enctype="multipart/form-data">

.....

....

<input type="file" name="logo"/>

...


.....

somewhere had some dodgy code I deleted

....

</form>

Thanks for the help. 谢谢您的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM