这是我在这里发表stackoverflow的第一篇文章。我在这个网站上搜索了这个问题的其他解决方案,但无法找到任何解决方案。我甚至与GoDaddy支持进行了广泛的会议,但是没有成功。
这是我的代码,它从PHP引用中略微修改:
<html>
<body>
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
if (isset($_POST['submit'])){
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$tmpfile = $_FILES['userfile']['tmp_name'];
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'File name: '.$uploadfile."\r\n";
echo 'Temp file: '.$tmpfile."\r\n\r\n";
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
}
}
?>
<form enctype="multipart/form-data" action="#" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" name="submit" id="submit" value="Send File" />
</form>
</body>
</html>
上传文件时的输出是:
Warning: move_uploaded_file(uploads/Bender.jpg): failed to open stream: No such file or directory in /home/nflaum/public_html/_working/file_upload.php on line 15
Warning: move_uploaded_file(): Unable to move '/tmp/phpWmeSDx' to 'uploads/Bender.jpg' in /home/nflaum/public_html/_working/file_upload.php on line 15
Possible file upload attack! File name: uploads/Bender.jpg Temp file: /tmp/phpWmeSDx
Here is some more debugging info:Array (
[userfile] => Array
(
[name] => Bender.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpWmeSDx
[error] => 0
[size] => 91463
)
)
以下是我已经尝试过的事情:
创建了我自己的php.ini文件并尝试了upload_tmp_dir的所有组合(使用phpinfo进行验证),无论是我自己还是GoDaddy代表。已验证的file_uploads已启用且所有设置均正常。
已验证文件夹对每个尝试过的组合都有777权限。
尝试重命名.htaccess以防某些路由配置导致问题。
连接到SSH并检查root / tmp文件夹以查看它是否存在(GoDaddy将主文件夹设置为/ home /)
没有一个解决了这个问题。看起来PHP认为文件正在正确上传,但它无处可寻。我希望这个论坛上的一位天才能够帮助我看到我错过的东西。
答案 0 :(得分:0)
我认为脚本当前位置的路径不正确。你检查过了吗?是文件夹&#34;上传&#34;在file_upload.php脚本的同一目录中?