0
votes

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??

2
You need to change permissions for the Webserver (APACHE | NGNINX | ..etc..) on those folders. or make him the owner - Linial
chmod doesn't do much on a windows system. - Marc B

2 Answers

0
votes

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.

0
votes

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);