douyudouchao6779 2015-07-08 20:41
浏览 34
已采纳

PHP POST方法上传[关闭]

I'm having trouble debugging why the processing of my file upload is not working. I've created a HTML5 file uploader on my page which calls my 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.
";
} else {
    echo "Possible file upload attack!
";
}

echo 'Here is some more debugging info:';

print_r($_FILES);

print "</pre>";    

The result of my debug shows me the following:

enter image description here

move_uploaded_file appears to return false and thus not being able to move the uploaded file from temp location to my specified location.

I've made sure to set the permissions on the folder where my upload.php resides and where the file should be save to 777.

Question Is there any way to get more information about why the file was not saved to help me understand what i did wrong ?

  • 写回答

1条回答 默认 最新

  • dsfhe34889 2015-07-08 21:01
    关注
    // File should be saved in same folder as upload.php
    $uploaddir = '/';
    

    /something is an absolute path; $uploaddir points to the root of your file system (that's not the same as the document_root of the webserver). The webserver process most likely doesn't have write permissions there.

    Take a look at the __DIR__ "constant" at http://php.net/language.constants.predefined

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在matlab里使用raven工具?
  • ¥100 关于ios手游充值到一定金额,再点充值提示公众号的问题。
  • ¥15 求一个stm32串口控制程序
  • ¥20 Windows 驱动开发版本疑问相关
  • ¥15 MAC 未能打开磁盘映像
  • ¥15 fastcap使用,二维导体输入问题
  • ¥15 hosts修改后不能访问
  • ¥15 关于化学反应速率C++编译问题/FLUENT
  • ¥20 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面