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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵