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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.