我无法调试为什么我的文件上传处理无效。我在我的网页上创建了一个HTML5文件上传器,它调用了我的upload.php。
upload.php
// File should be saved in same folder as upload.php
$uploaddir = '/';
$uploadfile = $uploaddir . basename($_FILES['fileToUpload']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
我的调试结果显示以下内容:
move_uploaded_file似乎返回false,因此无法将上传的文件从临时位置移动到指定位置。
我确保在upload.php所在的文件夹中设置权限,并将文件保存到777.
问题 有没有办法获得有关文件未保存原因的更多信息,以帮助我理解我做错了什么?
答案 0 :(得分:1)
// File should be saved in same folder as upload.php
$uploaddir = '/';
/something
是absolute path; $ uploaddir指向文件系统的根目录(与Web服务器的document_root不同)。 Web服务器进程很可能在那里没有写权限。
看看__DIR__&#34;常数&#34;在http://php.net/language.constants.predefined