关于php 文件上传错误的问题!!!! [100分 在线急等]
网站急需文件上传功能
可move_uploaded_file()函数测试没通过
服务器相关设置不很明确 不过文件上传应该是开了 php4.3
不知道是不是和虚拟主机有关?
请各位高人指点 多谢 小弟很急!!
相关代码及信息如下:
代码:
<?php
// 在 4.1.0 以前的 PHP 中,需要用 $HTTP_POST_FILES 代替 $_FILES。
// 在 4.0.3 以前的 PHP 中,需要用 copy() 和 is_uploaded_file() 来代替 move_uploaded_file()。
$uploaddir = '/home/gonghui/wwwroot/testsite/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
print "File is valid, and was successfully uploaded. Here's some more debugging info:\n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}
print "</pre>";
?>
提交表单:
<form action="upload.php" name="uploadform" enctype="multipart/form-data" method="post">
<input type="file" name="userfile">
<input type="submit" name="submit" value="submit">
</form>
错误信息:
Warning: move_uploaded_file(/home/gonghui/wwwroot/testsite/sb.jpg) [function.move-uploaded-file]: failed to create stream: Permission denied in /home/gonghui/wwwroot/testsite/upload.php on line 8
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpNDX1Jt' to '/home/gonghui/wwwroot/testsite/sb.jpg' in /home/gonghui/wwwroot/testsite/upload.php on line 8
Possible file upload attack! Here's some debugging info:
Array
(
[userfile] => Array
(
[name] => sb.jpg
[type] => image/pjpeg
[tmp_name] => /tmp/phpNDX1Jt
[error] => 0
[size] => 7398
)
)