1

我正在尝试从网页制作一个简单的上传应用程序:localhost/test.html。我收到这些错误:

警告:move_uploaded_file(test/Blue hills.jpg):无法打开流:第 11 行的 C:\wamp\www\test.html 中没有这样的文件或目录

警告:move_uploaded_file(): Unable to move 'C:\wamp\tmp\php376.tmp' to 'test/Blue hills.jpg' in C:\wamp\www\test.html on line 11

这是我的代码

<html>
  <form enctype="multipart/form-data" action="test.html" method="POST">
    Please choose a file: <input name="uploaded" type="file" /><br />
    <input type="submit" value="Upload" />
 </form>
<html>

<?php

$target = "test/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
  echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else {
  echo "Uploading Error.";
}
4

3 回答 3

2

可能该目录test不存在。将这些行添加到您的代码中。

if (file_exists('test/')) echo 'Ok it wasn\'t that';
else echo 'Um, create a directory called test here: '.dirname(__FILE__);
于 2012-12-08T22:20:30.577 回答
0

确保test/你的脚本所在目录下存在a目录,然后就可以使用了

$out = dirname(__FILE__) . '/' . $_FILES['uploaded']['name'];
move_uploaded_file($_FILES['uploaded']['tmp_name'], $out);
于 2012-12-08T22:23:23.483 回答
0

将目录权限 (CHMOD) 更改为777通过您的 FTP 客户端(所有者、组、公共的读取、写入、执行)。

于 2012-12-08T23:08:06.563 回答