fife Posted June 23, 2011 Share Posted June 23, 2011 Im trying to just simply upload an image and the insert it into my database. I have my code which I have stripped all error checking out. When it runs the page refreshs but the file does not appear in the folder and the table is not updating. There are no server log errors or anything can someone help please... This will be an update form eventually but for now Im just trying to insert the image if (isset($_POST['update_field'])) { // // $intro = trim($_POST['intro']); // $intro = mysql_real_escape_string($intro); // $intro = mysql_query("UPDATE clubsstuff SET intro = '$intro' WHERE ID = '".$intro['cID']."' ") or die(mysql_error()); //another photo uploader $fileName = $_FILES['intro_image']['name']; $tmpName = $_FILES['intro_image']['tmp_name']; $fileSize = $_FILES['intro_image']['size']; $fileType = $_FILES['intro_image']['type']; $randName =$User['memberID'].md5(rand() * time()); $FileName = $randName; $folder = "/members/images/{$intro['county']}/"; //if ($FileSize >250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>"; //$file_upload="false";} // // } // // if (!($FileType =="image/jpeg" OR $intro_image_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>"; //$file_upload="false";} move_uploaded_file($tmpName , "$folder".$FileName.$fileType) or die(mysql_error()); //connect to database again include('../../Connections/database.php'); $FileName; $time = time(); $qInsert = "INSERT INTO `images` (`image_name`, `creationDate`, user,c ID, album_id, intro_image) VALUES ('$FileName', '$time', '".$User['member_ID']."', '".$intro['cID']."', '1', 'yes')"; $rInsert = mysql_query($qInsert) or die(mysql_error()); //Tells you if its all ok $url = "edit.php"; header("Location: ".$url.""); and the form <form action="" method="POST" enctype="multipart/form-data" name="c_image"> <input type="file" name="intro_image" id="intro_image"> <input type="submit" name="update-field" id="update-field" value="Update"> Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/ Share on other sites More sharing options...
AMcHarg Posted June 23, 2011 Share Posted June 23, 2011 Is the database field a medium_blob? Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233844 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 if you mean for the image no. Its just a varchac of length 200 for now. Its not getting that far though as the image is not appearing on the server either. Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233848 Share on other sites More sharing options...
gristoi Posted June 23, 2011 Share Posted June 23, 2011 if you put your error handler on at the top of your script do you still get no errors or warnings showing? ini_set('display_errors',1); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233852 Share on other sites More sharing options...
PFMaBiSmAd Posted June 23, 2011 Share Posted June 23, 2011 Your submit button is named - name="update-field". You would to test that same named $_POST variable. You have $_POST['update_field'], which does not match the name of your form field. Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233855 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 I get this....... edit_vsvb0n90nx.php on line 14 but that refers to a query that I know works fine as was already on the page. I dont understand the _vsvb0n90nx.php as the page is just called edit.php with nothing after it Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233856 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 Ok thank you PFMaBiSmAd but I now have this error. This is my first image uploader so I have no idea how to trouble shoot it. ive pinched and wrote my own code. The uploady part was from a tut so I cant see whats up with it Warning: move_uploaded_file(/members/images/Lancashire/000000000354ca08848008b86f5057364ae0dc09b8.image/jpegimage/jpeg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/sites/site.com/public_html/members/edit/edit.php on line 37 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpTFdk4s' to '/members/images/Lancashire/000000000354ca08848008b86f5057364ae0dc09b8.image/jpegimage/jpeg' in /home/sites/site.com/public_html/members/edit/edit.php on line 37 line 37 is move_uploaded_file($tmpName , "$folder".$FileName.$fileType) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233858 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 ive tried put in ../../ to send the $folder back to the root but same error Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233859 Share on other sites More sharing options...
PFMaBiSmAd Posted June 23, 2011 Share Posted June 23, 2011 See this post - http://www.phpfreaks.com/forums/index.php?topic=336242.msg1583862#msg1583862 Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233863 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 right I noticed it had the file type on it twice so I changed the move upload file code to move_uploaded_file($tmpName , "$folder".$FileName) or die(mysql_error()); Im still getting the error that says the directory does not exist. Which is not true. The directory that it is referring to does exist on the server. Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233866 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 cool thanks again but if I put $_SERVER["DOCUMENT_ROOT"] at the front of the string $folder = "".$_SERVER["DOCUMENT_ROOT"]."members/images/{$intro['county']}/"; it error again but the path looks as follows........... http://www.site.com/public_html/members/images/lancashire/000000000324587b2446acd77b5a31fca2e7fec2fc.image/jpeg Obviously public shoud not be there Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233879 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 if you put /members then the path looks perfect on the error that it generates Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233892 Share on other sites More sharing options...
PFMaBiSmAd Posted June 23, 2011 Share Posted June 23, 2011 The link I posted stated that a leading / on a file system path refers to the root of the current hard disk. Do you know what the root of the current hard disk means? If your $_SERVER["DOCUMENT_ROOT"] contains http://www, then who ever setup the virtual host configuration on your server didn't know what they should set it to. Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233898 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 yes I know what the root mean. My site is hosted from Heart Internet. A massive company in which My words would have no effect over. If im in the folder /members/edit and my page is called edit. Then surely to reference an image from the root it would be /images or even ../images Other images and files on the site are used this way so why when I write $folder = "/members/images/{$intro['county']}/"; does it say the path does not exist and why even if i type it not go from. http://www.thesite.com/members/images/ (image name here) does it still give me a server error like so.............. [Thu Jun 23 18:49:04 2011] [error] [client 94.5.254.197] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpWwYpSt' to 'http://www.site.com/members/images/Lancashire/0000000003d75b6a81a8c42da6028c835dd7cda019.image/jpeg' in /home/sites/site.com/public_html/members/edit/edit-club-intro.php on line 35, referer: http://www.site.com/members/edit/edit-club-intro.php Maybe I dont understand properly as im really confused now. Can somebody at least explain the previous post or the error above? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233936 Share on other sites More sharing options...
fife Posted June 23, 2011 Author Share Posted June 23, 2011 is it possible the file name is wrong. it looks as follows 0000000003253a8ba618e5490569e878696d3b20f1.image/jpeg' Quote Link to comment https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233942 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.