file upload issues

Reply

Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

file upload issues

 
0
  #1
Sep 15th, 2008
I'm trying to upload .js files onto my sever. This is the code:
  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:
  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?
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 438
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: file upload issues

 
0
  #2
Sep 16th, 2008
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:
  1. error_reporting(E_ALL);
  2. ini_set('display_errors', true);
See if that produces a more helpful error message.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

Re: file upload issues

 
0
  #3
Sep 16th, 2008
may be permission error of destination directory
Help as an alias

I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 401
Reputation: CoolGamer48 is on a distinguished road 
Solved Threads: 40
CoolGamer48's Avatar
CoolGamer48 CoolGamer48 is offline Offline
Posting Pro in Training

Re: file upload issues

 
0
  #4
Sep 16th, 2008
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.
I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 438
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: file upload issues

 
0
  #5
Sep 17th, 2008
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC