PHP move_uploaded_file失败。上传的文件tmp_name是空白的?

时间:2014-10-13 22:55:42

标签: php upload

好的,所以我有以下代码可以移动上传的文件。我已经创建了这个目录,并在其上运行了一个if file_exists,以确保php可以看到它(它可以)。此代码失败,并显示以下错误:

[13-Oct-2014 18:52:07 America/New_York] PHP Warning:  fopen(C:\inetpub\wwwroot\PHPTesting\uploads\tr.apk): failed to open stream: No such file or directory in C:\inetpub\wwwroot\PHPTesting\main.php on line 395
[13-Oct-2014 18:52:07 America/New_York] PHP Warning:  filesize(): stat failed for C:\inetpub\wwwroot\PHPTesting\uploads\tr.apk in C:\inetpub\wwwroot\PHPTesting\main.php on line 396
[13-Oct-2014 18:52:07 America/New_York] PHP Warning:  fread() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\PHPTesting\main.php on line 396
[13-Oct-2014 18:52:07 America/New_York] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in C:\inetpub\wwwroot\PHPTesting\main.php on line 397

目录中没有文件。我真的无法弄清楚为什么它失败了,我甚至更改了权限,以便任何人都可以写入它。此外,如果我回显tmp名称,它什么也不返回。

代码:

$uploaddir = "C:\\inetpub\\wwwroot\\PHPTesting\\uploads\\";
$uploadfile = $uploaddir.$_FILES['Attachment']['name'];
echo $uploadfile;
if (move_uploaded_file($_FILES['Attachment']['tmp_name'], $uploadfile))
echo "File uploaded.";
else
echo "File failed.". $_FILES['Attachment']['name'];

输出:

C:\的Inetpub \ wwwroot的\ PHPTesting \上传\ tr.apk。文件失败tr​​.apk

HTML表格:

<form action="main.php"  name="sendMessageform" method="post" enctype="multipart/form-data">
<input type="hidden"  value="sendMessage" name="action">
To:<input type="text" name="To"><br/>
Cc:<input type="text" name="Cc"><br/>
Bcc:<input type="text" name="Bcc"><br/>
Subject:<input type="text" name="Subject"></br>
Message:<input type="textarea" rows="4" cols="50" name="Message"><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="30000000" />
Attachment:<input type="file" name="Attachment"><br/>
<input type="submit" value="Send Message">
</form>

0 个答案:

没有答案