[英]move_uploaded_file(uploads/) [function.move-uploaded-file]: failed to open stream: Permission denied
I have this code : 我有这个代码:
chmod('uploads', 0777);
$image = $_FILES['image']['tmp_name'];
$_FILES['image']['name'] = date('d-m-Y_H-i-s-') . rand(11111,99999) * rand(99999,11111) . rand(111,999) . $_FILES['image']['tmp_name'];
and this : 和这个 :
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/');
but when I run the code I get this error message: 但是当我运行代码时,出现以下错误消息:
Warning: move_uploaded_file(uploads/) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\\AppServ\\www\\tab\\submit.php on line 51 警告:move_uploaded_file(uploads /)[function.move-uploaded-file]:无法打开流:第51行的D:\\ AppServ \\ www \\ tab \\ submit.php中的权限被拒绝
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\\Windows\\Temp\\php4D3.tmp' to 'uploads/' in D:\\AppServ\\www\\tab\\submit.php on line 51 警告:move_uploaded_file()[function.move-uploaded-file]:无法将D:\\ AppServ \\ www \\ tab \\ submit.php中的'C:\\ Windows \\ Temp \\ php4D3.tmp'移动到'uploads /' 51
How to fix it?? 如何解决?
Probably apache's user is not the owner of this folder. apache的用户可能不是此文件夹的所有者。 Try to change it's owner or add the apache user to the group that has write permission on it. 尝试更改其所有者或将apache用户添加到对其具有写权限的组。
Other thing is, you need just the write permission on it, be careful with 0777 permissions. 另一件事是,您只需要对其具有写权限,请谨慎使用0777权限。
I successed to fix it!! 我成功修复了它!
Just replace: 只需替换:
$_FILES['image']['name'] = date('d-m-Y_H-i-s-') . rand(11111,99999) * rand(99999,11111) . rand(111,999) . $_FILES['image']['tmp_name'];
to 至
$file_name = date('d-m-Y_H-i-s-') . rand(11111,99999) * rand(99999,11111) . rand(111,999) . $_FILES['image']['name'];
and 和
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/');
to 至
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/'.$file_name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.