andy_b_1502 Posted February 9, 2012 Share Posted February 9, 2012 Hi everyone! I'm trying to create a form with an upload photo bit in it. The photo i know, has to be saved on the server somewhere. Iv'e created an images folder both in my host's control pannel and in my dreamwever files and FTP'd it to the server. I've tried both ways of sending the test .jpg to each folder but i'm getting the desgined mySQL error. What's going worng here? <?php //This is the directory where images will be saved $target = "/images/COMPANIES"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['photo']['name']); // Connects to your Database mysql_connect("******host", "****username", "****password") or die(mysql_error()) ; mysql_select_db("****DB") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/ Share on other sites More sharing options...
scootstah Posted February 9, 2012 Share Posted February 9, 2012 So what's the error? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316209 Share on other sites More sharing options...
andy_b_1502 Posted February 9, 2012 Author Share Posted February 9, 2012 Sorry, there was a problem uploading your file i dont know whats causing it though?? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316219 Share on other sites More sharing options...
andy_b_1502 Posted February 9, 2012 Author Share Posted February 9, 2012 just add, after turning error reporting on the following error message(s) are displayed: Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 5 Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 12 Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 22 Sorry, there was a problem uploading your file. Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316221 Share on other sites More sharing options...
scootstah Posted February 9, 2012 Share Posted February 9, 2012 Can you show me what this gives you: echo '<pre>' . print_r($_FILES, true) . '</pre>'; It needs to be run when the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316228 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 echo '<pre>' . print_r($_FILES, true) . '</pre>'; To display the variable?? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316381 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 Parameters expression The expression to be printed. return If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to TRUE, print_r() will return the information rather than print it. Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316383 Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 Are you using 'photo' or 'uploadedfile' in your form? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316386 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 photo Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316388 Share on other sites More sharing options...
bspace Posted February 10, 2012 Share Posted February 10, 2012 well it looks like a problem with 'photo' somewhere show us the form code Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316394 Share on other sites More sharing options...
scootstah Posted February 10, 2012 Share Posted February 10, 2012 echo '<pre>' . print_r($_FILES, true) . '</pre>'; To display the variable?? I want you to put that code in your script and then post back what it outputs. It should contain all of the data associated with $_FILES. Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316401 Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 Adding $_FILES['photo']['error'] will show an error number (good or bad), which can identify what's going on. See error codes here. http://php.net/manual/en/features.file-upload.errors.php Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316409 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 Scootstah, adding that in my script returns this: "Array ( [upload] => Array ( [name] => Zodiac_Sign_Tattoo___Aquarius_by_MPtribe.jpg [type] => image/jpeg [tmp_name] => /tmp/phpfXyUCg [error] => 0 => 26389 ) ) Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 9 Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 16 Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26 Sorry, there was a problem uploading your file. " The form code is this: <form enctype="multipart/form-data" action="basicpackage-send.php" method="POST"> Compnany Name:<br /> <input type="text" name="company_name"><br> Company Description:<br /> <input type="text" name = "basicpackage_description"><br> Location:<br /> <input type="text" name = "location"><br> Postcode:<br /> <input type="text" name = "postcode"><br> Company Logo/Photo:<br /> <input type="file" name="upload"><br> <input type="submit" value="Add"> </form> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316517 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 update from my host's tech support: " Hello, Thank you for contacting Support. On our platform, root is the home directory path. You can upload the image files into the root directory of your account. If you are using any script, then you can use the home directory path: /home/users/web/b109/ipg.removalspacecom . Thank you! Sincerely, Lakeshia Sidwick Customer Support" is this the path i need to put in my script for the images to go to or not? do i create a folder here? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316521 Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 In your form you are using <input type="file" name="upload"> So "upload" is the name you're using. In processing, you need to use this same name. <?php //This is the directory where images will be saved $target = "/images/COMPANIES/"; $filename = stripslashes($_FILES['upload']['name']); $target = $target.$filename; //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=$filename; // Connects to your Database mysql_connect("******host", "****username", "****password") or die(mysql_error()) ; mysql_select_db("****DB") or die(mysql_error()) ; //Writes the information to the database $company_name = mysql_real_escape_string($company_name); $basicpackage_description = mysql_real_escape_string($basicpackage_description); $location = mysql_real_escape_string($location); $postcode = mysql_real_escape_string($postcode); $upload = mysql_real_escape_string($upload); mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". $_FILES['upload']['name']. " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316678 Share on other sites More sharing options...
litebearer Posted February 10, 2012 Share Posted February 10, 2012 Two added suggestions... 1. put your query into a string, then execute it. makes its easier check query values. 2. due the query AFTER successful upload Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316691 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 thank you for that help. where does this "upload" photo/picture go to? After just testing out the new code i'm getting these error messages: "Array ( [upload] => Array ( [name] => 360mainhead.jpg [type] => image/jpeg [tmp_name] => /tmp/phpINBhZP [error] => 0 => 15625 ) ) Notice: Undefined index: photo in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 16 Warning: move_uploaded_file(/home/users/web/b109/ipg.removalspacecom360mainhead.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpINBhZP' to '/home/users/web/b109/ipg.removalspacecom360mainhead.jpg' in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26 Sorry, there was a problem uploading your file." It looks like it's having trouble sending it to the server but i have permissions to do this as i've contacted my host's tech support to clear it up? i'm told it just goes to the root directory of my server. Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316704 Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 Where are you using 'photo' still? Undefined index: photo in ... basicpackage-send.php on line 16 Thought we had name changed to 'upload'? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316705 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 there was a 'photo' on line 16 but i changed that now to 'upload' the error messages are these: "Array ( [upload] => Array ( [name] => 360mainhead.jpg [type] => image/jpeg [tmp_name] => /tmp/phpe1KDpI [error] => 0 => 15625 ) ) Warning: move_uploaded_file(/home/users/web/b109/ipg.removalspacecom360mainhead.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpe1KDpI' to '/home/users/web/b109/ipg.removalspacecom360mainhead.jpg' in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 26 Sorry, there was a problem uploading your file." how do i change permissions? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316714 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 it's okay i've had a look. i wasnt using the correct path, which i am now. Thank you for all your help!! Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316717 Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 Is the folder(directory) 'images' in you base folder? Meaning MyDomain.com/images Or is the "path" relative to the processing file? If relative try $target = "images/COMPANIES/"; $filename = stripslashes($_FILES['upload']['name']); $target = $target.$filename; Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316719 Share on other sites More sharing options...
andy_b_1502 Posted February 10, 2012 Author Share Posted February 10, 2012 the folder is in my filemanger on my host's control panel, i thought that's where it had to be sent? I've selected topic not solved as now the other varibales of my form are not being upadted in mySQL? but the image is being sent to the folder just fine??? here's the form code again: <form enctype="multipart/form-data" action="basicpackage-send.php" method="POST"> Compnany Name:<br /> <input type="text" name="company_name" id="company_name"><br> Company Description:<br /> <input type="text" name = "basicpackage_description" id="basicpackage_description"><br> Location:<br /> <input type="text" name = "location" id="location"><br> Postcode:<br /> <input type="text" name = "postcode" id="postcode"><br> Company Logo/Photo:<br /> <input type="file" name="upload" id="upload"><br> <input type="submit" value="Add"> </form> php code: <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("host", "username", "password") or die(mysql_error()) ; mysql_select_db("DBname") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Before the upload bit was created, the other parts of the form went straight in to mySQL on testing?? Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316728 Share on other sites More sharing options...
Drummin Posted February 10, 2012 Share Posted February 10, 2012 More than likely INSERT is failing because $target is not escaped. <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("host", "username", "password") or die(mysql_error()) ; mysql_select_db("DBname") or die(mysql_error()) ; //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; $company_name = mysql_real_escape_string($company_name); $basicpackage_description = mysql_real_escape_string($basicpackage_description); $location = mysql_real_escape_string($location); $postcode = mysql_real_escape_string($postcode); $upload = mysql_real_escape_string($upload); //Writes the information to the database mysql_query("INSERT INTO `Companies` VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") or die(mysql_error()); } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316735 Share on other sites More sharing options...
scootstah Posted February 10, 2012 Share Posted February 10, 2012 Under the query run echo mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316736 Share on other sites More sharing options...
andy_b_1502 Posted February 11, 2012 Author Share Posted February 11, 2012 The echoed error is this: Array ( [upload] => Array ( [name] => 360mainhead.jpg [type] => image/jpeg [tmp_name] => /tmp/php4eoXyy [error] => 0 => 15625 ) ) Column count doesn't match value count at row 1The file 360mainhead.jpg has been uploaded, and your information has been added to the directory Quote Link to comment https://forums.phpfreaks.com/topic/256754-saving-picturesphotos-on-the-server/#findComment-1316961 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.