943,706 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 772
  • PHP RSS
Sep 15th, 2008
0

file upload issues

Expand Post »
I'm trying to upload .js files onto my sever. This is the code:
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title>Add Ubiquity Command</title>
  4. </head>
  5. <body>
  6. <form action="add_ubiquity_cmd.php" method="post" enctype="multipart/form-data">
  7. Name: <input type="text" name="name" /><br />
  8. Description: <textarea rows="8" cols="30" name="description"></textarea><br />
  9. JS File: <input type="file" name="file"><br />
  10. <input type="submit" value="Add Command" /><br/>
  11. </form>
  12. <?php
  13. if(isset($_POST["name"]))
  14. {
  15. $con = mysql_connect("localhost", "usr", "pass");
  16. mysql_select_db("alecbenz_general");
  17.  
  18. if($_FILES["file"]["error"] > 0)
  19. {
  20. echo "Error: ".$_FILES["file"]["error"];
  21. }
  22. elseif($_FILES["file"]["type"] != "application/x-javascript")
  23. {
  24. echo "Error: file not a Javascript file";
  25. }
  26. elseif(file_exists("../ubiquity/".$_FILES["file"]["name"]))
  27. {
  28. echo "Error: filename already being used.";
  29. }
  30. else
  31. {
  32. if(!(move_uploaded_file($_FILES["file"]["tmp_name"],"/ubiquity/".$_FILES["file"]["name"])))
  33. {
  34. $error = error_get_last();
  35. echo "Error uploading file:<br />Type:".$error["type"]."<br />Message:".$error["message"];
  36. }
  37. else
  38. {
  39. echo "File uploaded<br />";
  40. $sql = "INSERT INTO ubiquity_cmds (name,description,js_filename) VALUES(".$_POST["name"].",".$_POST["description"].",".$_FILES["file"]["name"].")";
  41. if(mysql_query($sql,$con))
  42. {
  43. echo "Command added";
  44. }
  45. else
  46. {
  47. echo "Error adding command: ".mysql_error();
  48. }
  49. }
  50. }
  51. }
  52. ?>
  53. </body>
  54. </html>

I get this error:
PHP Syntax (Toggle Plain Text)
  1. Error uploading file:
  2. Type:2
  3. Message:move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpuveovn' to '/ubiquity/cmd_echo.js'

Anyone know what a possible problem might be?
Similar Threads
Reputation Points: 77
Solved Threads: 40
Posting Pro in Training
CoolGamer48 is offline Offline
401 posts
since Jan 2008
Sep 16th, 2008
0

Re: file upload issues

My first guess would be that you don't have write permission on the destination directory.

Try turning on the debug messages by putting this at the top of your page:
php Syntax (Toggle Plain Text)
  1. error_reporting(E_ALL);
  2. ini_set('display_errors', true);
See if that produces a more helpful error message.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Sep 16th, 2008
0

Re: file upload issues

may be permission error of destination directory
Reputation Points: 15
Solved Threads: 21
Posting Whiz in Training
nikesh.yadav is offline Offline
219 posts
since Feb 2008
Sep 16th, 2008
0

Re: file upload issues

I think I found my problem. For some reason, doing /ubiquity/ doesn't work. I'm under the impression that / would be my public_html directory, and so /ubiquity/ would be public_html/ubiquity/. Anyway, I changed it to ../ubiquity/ (the folder I'm in is also located in public_html), and I don't get an error with the file move.
Reputation Points: 77
Solved Threads: 40
Posting Pro in Training
CoolGamer48 is offline Offline
401 posts
since Jan 2008
Sep 17th, 2008
0

Re: file upload issues

On a Linux server, prefixing any path with / will make it start at the root directory.

So your /ubiquity/ path would look for a folder called ubiquity directly under the root.

This is different for URL's, where / will have the browser start at the web root.
Like, for example, if you had an <a> href /page.php in a page at www.example.com/path/to/page.html , it would send you to www.example.com/page.php .
Last edited by Atli; Sep 17th, 2008 at 4:59 am. Reason: spelling
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 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: Mail error?
Next Thread in PHP Forum Timeline: want to insert the image background





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


Follow us on Twitter


© 2011 DaniWeb® LLC