943,879 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2662
  • PHP RSS
Nov 24th, 2008
0

File Upload Error

Expand Post »
Hi!

I am using the following code for a file upload-

php Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3.  
  4.  
  5. if(isset($_POST['b1']))
  6. {
  7.  
  8. if($_FILES['uploadedfile']['name'] !="")
  9. {
  10. $target_path = "/home/infotech/myhomepage/uploads/";
  11. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
  12. echo("Temporary Location is: ".$_FILES['uploadedfile']['tmp_name']."<br />");
  13. echo("Target Path is: ".$target_path."<br />");
  14. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
  15.  
  16. echo "The file ". basename( $_FILES['uploadedfile']['name']).
  17. " has been uploaded";
  18. }
  19.  
  20. else{
  21. echo "There was an error uploading the file, please try again!";
  22. }
  23.  
  24. }
  25. else
  26. {
  27. die("No file specified");
  28. }
  29. }
  30. ?>
  31.  
  32.  
  33.  
  34. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  35. <html xmlns="http://www.w3.org/1999/xhtml">
  36. <head>
  37. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  38. <title>File Upload</title>
  39. </head>
  40.  
  41. <body>
  42. <form enctype="multipart/form-data" action="<?php echo($_SERVER['PHP_SELF']);?>" method="POST">
  43. <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  44. Choose a file to upload: <input name="uploadedfile" type="file" /><br />
  45. <input type="submit" name="b1" value="Upload File" />
  46. </form>
  47. </form>
  48. </body>
  49. </html>

While it works fine on my localhost, when I upload it to the server, I get-

Temporary Location is: /tmp/phpw1v73L
Target Path is: /home/infotech/myhomepage/uploads/a.txt

Warning: move_uploaded_file(/home/infotech/myhomepage/uploads/a.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/infotech/myhomepage/upload.php on line 15

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpw1v73L' to '/home/infotech/myhomepage/uploads/a.txt' in /home/infotech/myhomepage/upload.php on line 15
There was an error uploading the file, please try again!

-----------

Is it due to permissions?

Because I am able to do mv /tmp/foo /home/infotech/myhomepage/uploads/
Any ideas?
Thanks
Similar Threads
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Nov 24th, 2008
0

Re: File Upload Error

I think this may be to do with permissions on the folder. Your permissions are not the same as php's permissions. The fix depends on what server you are using, but in a Linux server you can use a chmod command on the directory to change the permissions. You need write access for the Other group of permissions (the second-last bit). Use the command

chmod 766

to assign full access to the directory's owner, read/write access to the owner's group and read/write access to other users (which includes php/www).

I'm not sure about a windows server sorry, maybe someone else can help if you are using a windows server.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Nov 24th, 2008
0

Re: File Upload Error

Worked like a charm, thanks for your reply!
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: i need urgent help Parse error
Next Thread in PHP Forum Timeline: User based look & feel customization of site





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC