move_uploaded_file() 无法打开流:没有这样的文件或目录

2021-12-24 00:00:00 file-upload php

我已经完成了你的标准检查(目录是否在那里,权限设置是否足够宽松),而且我很确定我已经涵盖了你标准的愚蠢的人类技巧.这是失败的代码:

I've done your standard checks (is the directory there, are lax enough permissions set), and I'm pretty sure I've covered your standard stupid human tricks. Here's the code that's failing:

move_uploaded_file($_FILES['image1']['tmp_name'], "/public_html/flashsale/assets/img/products/T".$_FILES['image1']['name']);

目录在那里 - 我从 FileZilla 复制了路径.我什至在 FileZilla 和 HostGator 控制面板上的文件管理器中将权限设置为 777.此代码生成两个警告:

The directory is there - I copied the path from FileZilla. I even set the permissions to 777, both in FileZilla and in the file manager on the HostGator control panel. This code generates two warnings:

留言:move_uploaded_file(/public_html/flashsale/assets/img/products/Tsirloin.jpg)[function.move-uploaded-file]:无法打开流:没有那个文件或目录

Message: move_uploaded_file(/public_html/flashsale/assets/img/products/Tsirloin.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory

消息:move_uploaded_file() [function.move-uploaded-file]:无法将/tmp/phpI5GZ3S"移动到'/public_html/flashsale/assets/img/products/Tsirloin.jpg'

Message: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpI5GZ3S' to '/public_html/flashsale/assets/img/products/Tsirloin.jpg'

按照这个顺序.所以,文件正在上传,目录存在并设置为777,我还能缺少什么?

In that order. So, the file is being uploaded, the directory exists and is set to 777, what else could I be missing?

推荐答案

你不需要把完整的目录放到文件中.尝试从您的链接中删除 /public_html/flashsale/ 并查看它是否有效.另外文件不需要777权限,我自己上传文件到755权限的文件夹.

you do not need to put the full directory to the file. try to remove /public_html/flashsale/ from your link and see if that will work. In addition, the file does not need to have 777 permission, I myself upload files to folders with 755 permissions.

此外,您可以在目标目录中使用 getcwd();.该函数将为您提供移动文件所需的目录.来源

also, you can use getcwd(); in the directory your aiming to. the function will give you the directory that you need to use for moving your file. source

相关文章