0

I am trying to create a simple php image uploading form. I appear to have some kind of permissions problem though and I'm not sure how to fix this...

Here's my code...

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

upload_file.php...

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

Here's the error I get...

Stored in: upload/81350042.jpgPHP Warning: move_uploaded_file(upload/81350042.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\websites\tb123654\www\upload_file.php on line 27 PHP Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\upload\php5BFB.tmp' to 'upload/81350042.jpg' in D:\websites\tb123654\www\upload_file.php on line 27

2 Answers 2

2

open your ftp client, right click on the folder you upload things to, attributes or propieties, set permission to 777.

or

chmod 777 yourfolder

Sign up to request clarification or add additional context in comments.

5 Comments

I get the message "Setting access properties failed"
do you own the server and have console access or just a ftp access? what ftp client are you using(if any)?
I just have ftp access in this case, though I have access to another server with console access. I am using Dreamweaver.
Try changing permission to the folder with an access panel like CPanel if your hosting provider give it to you, or try to use php php.net/manual/en/function.chmod.php
OK... Apparently due to the level of hosting I have on this account I am unable to change these settings myself, but they have done it for me and now it works. Your advice will certainly help on other hosting packages I have though so thanks.
0

There is no folder called "uploads" in "D:\websites\tb1234\www\" so the images can't be moved there. I think that's what your script is trying to do. Try to use absolute paths and see if that works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.