PHP:move_uploaded_file():无法移动'/
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5023181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: move_uploaded_file(): Unable to move '/
提问by Matt Elhotiby
I keep getting this error on a new server I just setup
我在刚刚设置的新服务器上不断收到此错误
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Warning:
move_uploaded_file(upload/110216104651_00134_smooth_1440x900.jpg):
failed to open stream: Permission denied in /var/www/admin/_application/models/Roles.model on line 1757,
referer: http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Warning: move_uploaded_file():
Unable to move '/tmp/php6wlOg1' to 'upload/110216104651_00134_smooth_1440x900.jpg'
in /var/www/admin/_application/models/Roles.model on line 1757, referer:
http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
[Wed Feb 16 22:46:51 2011] [error] [client 71.1.236.114] PHP Notice:
Upload Error: Error moving from temp dir in /var/www/admin/_application/models/Roles.model on line 1759,
referer: http://nacc.biz/admin/admin/modifyarticle.php?roleid=4
I added 777 and created a uploads dir, but the error persists. How do I find the path that needs to either be corrected or created?
我添加了 777 并创建了一个上传目录,但错误仍然存在。如何找到需要更正或创建的路径?
回答by teecee
Change owner of upload/
to www-data:www-data
and also chmod to 755
将upload/
towww-data:www-data
和 chmod 的所有者更改为755
回答by pioniere
Looks like it doesn't know where upload/
is. Make sure you have the full path in your statement. For example, if upload directory is actually located in /var/upload
, then make sure that is in your statement, not just upload
/.
好像不知道在哪里upload/
。确保您的语句中有完整路径。例如,如果上传目录实际上位于 中/var/upload
,那么请确保它在您的语句中,而不仅仅是upload
/。
回答by RobertPitt
Log into your ftp and confirm the following:
登录您的 ftp 并确认以下内容:
- The folder exists, check for spellings
- Check the properties of the folder and make sure the permissions have read+write
0666
- Make sure the file is within your public html root, otherwise double check the owner of the file, and make sure PHP Has read / write access to it.
- 文件夹存在,检查拼写
- 检查文件夹的属性并确保权限具有读+写
0666
- 确保该文件位于您的公共 html 根目录中,否则请仔细检查该文件的所有者,并确保 PHP 对其具有读/写访问权限。
looking at the log:
查看日志:
Unable to move '/tmp/php6wlOg1' to 'upload/110216104651_00134_smooth_1440x900.jpg'
It seems to me that its looking in your root directory as upload/110216....
should be path.to/public_html/upload/110216....
在我看来,它upload/110216....
应该在您的根目录中查找path.to/public_html/upload/110216....
If none of the above work, please post your line of code that has move_uploaded_file
on.
如果以上都不起作用,请发布您的代码行move_uploaded_file
。
回答by meagar
It's trying to move the file to upload/
not uploads/
, make sure the directory exists and is writable.
它试图将文件移动到upload/
not uploads/
,确保目录存在且可写。
回答by MulleOne
Provided, there are no spelling mismatches, give your upload directory (that directory ONLY) all user rights sudo chmod a+rwx /path/to/folder
, that should fix the problem easily.
For a quick further read about permissions in Ubuntu, check here.
如果没有拼写不匹配,请为您的上传目录(仅该目录)提供所有用户权限sudo chmod a+rwx /path/to/folder
,这应该可以轻松解决问题。
要快速进一步了解 Ubuntu 中的权限,请查看此处。