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
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
How to fix it??
Probably apache's user is not the owner of this folder. Try to change it's owner or add the apache user to the group that has write permission on it.
Other thing is, you need just the write permission on it, be careful with 0777 permissions.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.