Jump to content

Script won't upload the image! Permission denied


EchoFool

Recommended Posts

Hi

 

 

I have an image uploading script that won't upload images...

 

 

It worked at one point when i had folder permission at 0777 but i was told that is risky so i changed it to 0775

 

 

Now it won't work and i can't use 0777.

 

 

 

 

Any one know what i need to do to get it to work?

 

This is my script:

<?php
$salt = 35322232414;
$name = $salt.$safe;


$name = md5($name);


if(isset($_POST['submit'])){ 
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 1000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo $_FILES["file"]["error"];
    }
  else
    {
   $filename = md5(serverdate()) . $_FILES["file"]["name"];
    if (file_exists("userimages/".$name."/".$filename))
      {
      echo "Image already uploaded!";
      }
    else
      {
   if (is_dir("userimages/".$name) == FALSE){
      mkdir("userimages/".$name, 0775); //permissions 
   }


   
      move_uploaded_file($_FILES["file"]["tmp_name"], "userimages/".$name."/" . $filename);
     echo "Image has been uploaded!";
      
}

 

 

Error i get:

 

Warning: move_uploaded_file(images/73640de25b7d656733ce2f808a330f18/7fc9cb9cf5ae1f7a5dd9105d3f9559fb_63.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in uploadfile.php on line 41

 

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpjrX3SO' to 'images/73640de25b7d656733ce2f808a330f18/7fc9cb9cf5ae1f7a5dd9105d3f9559fb_63.jpg' in uploadfile.php on line 4

Apply this php code on your uploads folder:

 

<?php

chown ("$your_uploads_folder", "$server_user");

?>

 

server_user is usually apache, data-www, httpd or some other server user that is allowed to upload files via php.

Ask your hosting company, they must know who that user is.

If you're having a permission error it means you do not have write access granted on the specific directory.

 

You can 1 - chown - change ownership of the directory (might work alone)

            2 - chmod - change permissions - if you own the dir you can probably set it as 0755 otherwise you may need to use 0775, I wouldn't recommend using 0777 for security issues.

 

Do you ssh into your server?? If so run an "ls -al" and you can see the current ownership and permissions.

Okay your talking beyond my level here i just made the script above it worked on 0777 - beyond that ive never really touched permissions ... all my other folders/files are 0755. Which is fine.

 

So were talking about alien stuff to me here :P If i change mod to 0755 it won't work when i did it manually.

The file and the folder the image uploads to all have the same name for the owner field.

 

upload.php is tghh[502]

folder "userimages" is tghh[502]

 

 

The other owner option is root[0] which has not been used but i don't think it would make a difference?

you probably need to review your  /etc/passwd file and find out which user php's process are being run by to be sure. You can also check /etc/group to see if you are in the necessary group/groups.

 

If this is getting too in depth, you should probably contact your sys admin.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.