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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?