By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,484 Members | 1,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,484 IT Pros & Developers. It's quick & easy.

file upload permission error

wadro21
P: 12
i am trying to write a php uploader for a site and keep getting this error:
Expand|Select|Wrap|Line Numbers
  1. Warning: move_uploaded_file(uploads61877494_tp.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/mysite/public_html/login/upload.php on line 5
  2.  
  3. Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKlOJBh' to 'uploads61877494_tp.jpg' in /home/mysite/public_html/login/upload.php on line 5
  4.  
I can run it fine on my local machine but when i upload it to the webserver it errors out. here is some example code:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. // Connects to Database 
  3. mysql_connect("localhost", "__MUNGED__", "__MUNGED__") or die(mysql_error()); 
  4. mysql_select_db("mysite_admin") or die(mysql_error());; 
  5.  
  6. //checks cookies to make sure they are logged in 
  7. if(isset($_COOKIE['ID_my_cookie'])) 
  8. $username = $_COOKIE['ID_my_cookie']; 
  9. $pass = $_COOKIE['Key_my_cookie']; 
  10. $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); 
  11. while($info = mysql_fetch_array( $check )) 
  12.  
  13. //if the cookie has the wrong password, they are taken to the login page 
  14. if ($pass != $info['password']) 
  15. { header("Location: login.php"); 
  16.  
  17. //otherwise they are shown the admin area 
  18. else 
  19. {
  20. echo "Admin Area<p>"; 
  21. echo "<a href=logout.php>Logout</a>";
  22. ?>
  23.  
  24. <fieldset>
  25.    <legend>File Upload</legend>
  26.    <p>
  27.  
  28.    <form enctype="multipart/form-data" action="upload.php" method="POST">
  29. Please choose a file: <input name="uploaded" type="file" /><br />
  30. <input type="submit" value="Upload" />
  31. </form> 
  32.  
  33.    </p>
  34.    </fieldset>
  35. ?>
  36.  
  37. upload.php
  38. <?php 
  39. $target = "uploads"; 
  40. $target = $target . basename( $_FILES['uploaded']['name']) ; 
  41. $ok=1; 
  42. if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
  43. {
  44. echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
  45. else {
  46. echo "Sorry, there was a problem uploading your file.";
  47. }
  48.  
  49. if ($uploaded_size > 350000)
  50. {
  51.  
  52.  
  53. echo "Your file is too large.<br>"; 
  54. $ok=0;
  55. ?>
  56.  
Aug 27 '07 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

This is not a problem with your code. This happens because you do not have permission to access the files you are trying to move.

Make sure you edit the permission on the folder you are moving your file into so that your script can write into it.

Also, use [code] tags when posting code. It is barely readable without them.
Aug 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.