Craigus Posted May 15, 2009 Share Posted May 15, 2009 Hello again Guru's. I've got a simple form to add info, text and an image to MySQL. It's all working correctly except the image upload. It seems to work but no matter what the filesize of the image the database shows the filesize [bLOB - 14 B] I'm not sure where I've gone wrong. Any help would be greatly appreciated. My insert.php; <?php //Connect to database mysql_connect("localhost","****_db","****") or die(mysql_error()) ; mysql_select_db("****_db") or die(mysql_error()) ; //Set variables $species = $_POST['species']; $location = $_POST['location']; $state = $_POST['state']; $date = $_POST['date']; $comments = $_POST['comments']; //No image selected, skip; if($_POST[image] == "none") { //Temporary file name stored on the server $tmpName = $_FILES['image']['tmp_name']; //Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); //continue from here if no image selected } else { //Insert into database $sql="INSERT INTO ****_db (image, species, location, state, date, latlong, comments) VALUES ('$image', '$species', '$location', '$state', '$date', '$latlong', '$comments')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } //Results echo "Thank you, your record has been added to the database"; } ?> Cheers Craig. Link to comment https://forums.phpfreaks.com/topic/158223-solved-strange-blob-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 15, 2009 Share Posted May 15, 2009 So the variable you are placing the image into is called $data. Where is that being used in your query? And your logic is wrong anyway. The if() {} is reading the data, the else {} is where the mysql query is at. Link to comment https://forums.phpfreaks.com/topic/158223-solved-strange-blob-problem/#findComment-834556 Share on other sites More sharing options...
Craigus Posted May 15, 2009 Author Share Posted May 15, 2009 So the variable you are placing the image into is called $data. Where is that being used in your query? Thank you.. And your logic is wrong anyway. The if() {} is reading the data, the else {} is where the mysql query is at. Please explain? I should also apologise for begin very new to this. ??? Link to comment https://forums.phpfreaks.com/topic/158223-solved-strange-blob-problem/#findComment-834562 Share on other sites More sharing options...
Craigus Posted May 15, 2009 Author Share Posted May 15, 2009 I've got this working by replacing This; $tmpName = $_FILES['image']['tmp_name']; $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); With this; $image =addslashes (file_get_contents($_FILES['image']['tmp_name'])); I guess I need to read more about use of if Thanks for the input. Craig. Link to comment https://forums.phpfreaks.com/topic/158223-solved-strange-blob-problem/#findComment-834566 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.