0

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

Falko
  • 17,076
  • 13
  • 60
  • 105
M0136466
  • 1
  • 1
  • 3
  • You need to change permissions for the Webserver (APACHE | NGNINX | ..etc..) on those folders. or make him the owner – Linial Aug 22 '14 at 16:10
  • possible duplicate of [move\_uploaded\_file gives "failed to open stream: Permission denied " error after all configurations i did](http://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error-after) – MoshMage Aug 22 '14 at 16:13
  • chmod doesn't do much on a windows system. – Marc B Aug 22 '14 at 16:14

2 Answers2

0

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.

vinibarr
  • 500
  • 3
  • 5
0

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);
M0136466
  • 1
  • 1
  • 3