简体   繁体   English

move_uploaded_file(uploads /)[function.move-uploaded-file]:无法打开流:权限被拒绝

[英]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.

相关问题 php警告:move_uploaded_file(../ images / uploads / tk13.JPG)[function.move-uploaded-file]:无法打开流:权限被拒绝 - php Warning: move_uploaded_file(../images/uploads/tk13.JPG) [function.move-uploaded-file]: failed to open stream: Permission denied 警告:move_uploaded_file [function.move-uploaded-file]:无法打开流:没有这样的文件或目录 - Warning: move_uploaded_file [function.move-uploaded-file]: failed to open stream: No such file or directory in move_uploaded_file 无法打开流:权限被拒绝 Mac - move_uploaded_file failed to open stream: Permission denied Mac move_uploaded_file 无法打开 stream:权限被拒绝 - Mac - move_uploaded_file failed to open stream: Permission denied - Mac move_uploaded_file无法打开流和权限被拒绝错误 - move_uploaded_file failed to open stream and Permission denied error move_uploaded_file给出:无法打开流:权限被拒绝 - move_uploaded_file gives: failed to open stream: Permission denied [function.move-uploaded-file]:无法打开流:没有这样的文件或目录 - [function.move-uploaded-file]: failed to open stream: No such file or directory [function.move-uploaded-file]:无法打开流:无效的参数 - [function.move-uploaded-file]: failed to open stream: Invalid argument PHP警告:move_uploaded_file():无法移动/无法打开流:权限被拒绝 - PHP Warning: move_uploaded_file(): Unable to move/failed to open stream: Permission denied 上传文件警告:move_uploaded_file(../ view / pictureswhy.PNG):无法打开流:权限被拒绝 - Upload file Warning: move_uploaded_file(../view/pictureswhy.PNG): failed to open stream: Permission denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM