twilitegxa Posted February 18, 2011 Share Posted February 18, 2011 I am trying to write this php code that is a form that allows the user to upload images along with a few other text fields. I keep getting this error when trying to upload the file to the server: Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpiPdn6u' to 'http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg' in /home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45 I have the code set up to tell me where the file is supposed to be uploaded, so it appears to upload kind of, but this error message and checking the actual folder on my server proves it doesn't get uploaded to it. I have had a code like this set up before and it worked, I just cannot find my files at the moment. Here is the code: the form: <form id="jewelry" name="jewelry" method="post" action="http://webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php" enctype="multipart/form-data"> <table id="jewelry" name="jewelry"> <tr> <td>Cut:</td> <td><input type="text" id="cut" name="cut" /></td> </tr> <tr> <td>Color:</td> <td><input type="text" id="color" name="color" /></td> </tr> <tr> <tr> <td>Carats:</td> <td><input type="text" id="carats" name="carats" /></td> </tr> <tr> <td>Clarity:</td> <td><input type="text" id="clarity" name="clarity" /></td> </tr> <tr> <td>Size Of Ring:</td> <td><input type="text" id="size" name="size" /></td> </tr> <tr> <td>Type Of Gold:</td> <td><input type="text" id="type" name="type" /></td> </tr> <tr> <td>Other Diamonds:</td> <td><input type="text" id="other" name="other" /></td> </tr> <tr> <td>Total Carats:</td> <td><input type="text" id="total" name="total" /></td> </tr> <tr> <td>Certificate Type:</td> <td><input type="text" id="certificate" name="certificate" /></td> </tr> <tr> <td>Appraisal Value:</td> <td><input type="text" id="value" name="value" /></td> </tr> <tr> <td>Upload Image:</td> <td><input type="file" id="file" name="file" /></td> </tr> <td colspan="2"><input type="submit" id="submit" name="submit" value="Submit" /> <input type="reset" id="reset" name="reset" value="Reset" /></td> </tr> </table> </form> the page that inserts it: <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'database'; mysql_select_db($dbname); $cut = $_POST['cut']; $color = $_POST['color']; $carats = $_POST['carats']; $clarity = $_POST['clarity']; $size = $_POST['size']; $type = $_POST['type']; $other = $_POST['other']; $total = $_POST['total']; $certificate = $_POST['certificate']; $value = $_POST['value']; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { 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("http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')"; $query_res = mysql_query($query) or die(mysql_error()); } } } else { echo "Invalid file"; } ?> Can anyone help me figure out how to get the image uploaded and saved into the upload folder on the server? Also, the filepath is not getting inserted into the table either for some reason, and not sure why. Please, can anyone help? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 18, 2011 Share Posted February 18, 2011 You can't move a file to a URL, you need to specify a location on the server's file system. Ken Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 18, 2011 Author Share Posted February 18, 2011 Can you give me some examples? I don't know what you mean? BTW - I fixed the issue with the path being inserted into the table, so it's just the issue of getting the actual file uploaded to the right place. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted February 18, 2011 Share Posted February 18, 2011 a path to a file is like: /usr/http/localhost/images/somefile.jpg Quote Link to comment Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 If you run this script from the root of your domain (webdesignsbyliz.com) the code should look like this: if (file_exists("wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')"; $query_res = mysql_query($query) or die(mysql_error()); } You should be able to use relative paths. Let me know how this works out for you. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 18, 2011 Author Share Posted February 18, 2011 Your code produced these two errors: Warning: move_uploaded_file(/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpdaKdwL' to '/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg' in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45 Stored in: http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg What am I doing wrong now? I have: <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'pass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'database'; mysql_select_db($dbname); $cut = $_POST['cut']; $color = $_POST['color']; $carats = $_POST['carats']; $clarity = $_POST['clarity']; $size = $_POST['size']; $type = $_POST['type']; $other = $_POST['other']; $total = $_POST['total']; $certificate = $_POST['certificate']; $value = $_POST['value']; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { 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("/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')"; $query_res = mysql_query($query) or die(mysql_error()); } } } else { echo "Invalid file"; } ?> Quote Link to comment Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 I checked your domain and i see the Wordpress is not located in the root of the domain, try this: Replace "wdbl_wordpress/wp-content/themes/twentyten_2/upload/" with "wp-content/themes/twentyten_2/upload/". if (file_exists("wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')"; $query_res = mysql_query($query) or die(mysql_error()); } Also make sure the `upload` folder has writing acces (777). Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 18, 2011 Author Share Posted February 18, 2011 Still getting the same errors pretty much :-( Warning: move_uploaded_file(wp-content/themes/twentyten_2/upload/dd.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpqs2yhv' to 'wp-content/themes/twentyten_2/upload/dd.jpg' in/home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php on line 45 Stored in: http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/dd.jpg I can't remember what I had to do differently before when I tried this very same thing. The only difference was it wasn't on a Wordpress installation, but I wouldn't think that would make a difference, so what else could it be? And yes, I have made sure the permissions were set :-) Quote Link to comment Share on other sites More sharing options...
eutu9 Posted February 18, 2011 Share Posted February 18, 2011 The problem is I can't figure out where is the script running from, I think this is the path of the script: /home/webdes17/public_html/wdbl_wordpress/wp-content/themes/twentyten_2/submit_jewelry.php If you could give me a link of the page where you use this upload script would be very helpful. Meanwhile try: 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: " . "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $image = "http://www.webdesignsbyliz.com/wdbl_wordpress/wp-content/themes/twentyten_2/upload/" . $_FILES["file"]["name"]; $query = "INSERT INTO gallery VALUES ('', '$cut', '$color', '$carats', '$clarity', '$size', '$type', '$other', '$total', '$certificate', '$value', '$image')"; $query_res = mysql_query($query) or die(mysql_error()); } Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted February 18, 2011 Author Share Posted February 18, 2011 The page is here: http://webdesignsbyliz.com/wdbl_wordpress/test-page/ I should have posted this in the beginning, but I completely forgot until now. I hope this helps you see what I am doing wrong. I know it's probably something so simple and something so stupid I am missing! LOL Thank you for all your help! BUT...whatever you just told em to do worked! Thank you soooooo much!!!! I'm going to look over it now and try to see what the heck I was doing wrong! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.