webent Posted June 25, 2008 Share Posted June 25, 2008 Could someone please take a look at my code and tell me what I am doing wrong? What I'm trying to do is insert all images, 50 at a time, there are more than 200,000, that are in a directory into a mysql database... Here's my code thus far... require "connection.php"; $dirname = "/home/username/public_html/storage/images/"; $new_destination = "/home/username/public_html/storage/inserted_images/"; $pattern = "(\.jpg$)|(\.JPG$)|(\.jpeg$)|(\.JPEG$)|(\.png$)|(\.PNG$)"; $files = array(); if (isset($_POST['insert_images'])) { if ($handle = opendir($dirname)) { while(false !== ($files = readdir($handle))) { $complete_image_path = $dirname . $files; $file_size = filesize($complete_image_path); list(,,$pattern) = getimagesize($complete_image_path); $file_type = image_type_to_extension($pattern); $file_name = $files; #################################################################### if ($file_type != "") { $insert_counter = 0; while ($insert_counter < 51) { $insert_counter++; // Do Insert 50 times $fp = fopen($complete_image_path, "rb"); $content = fread($fp, $file_size); $content = addslashes($content); $query = "INSERT INTO images VALUES ('$file_name', '$file_size', '$file_type', '$content')"; $result = mysql_query($query); if (!$results) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } // Move the image that was just inserted if(!move_uploaded_file($file_name, $new_destination)) { die; } fclose($fp); } } #################################################################### } } closedir($handle); } Here's a clip of the error, I cut it off, or it would go on for miles... Invalid query: Whole query: INSERT INTO images VALUES ('739-736-444736.jpg', '80232', '.jpeg', 'ÿØÿà\0JFIF\0\0\0d\0d\0\0ÿì\0Ducky\0\0\0\0\0<\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0 ÿÀ\0&&\0ÿÄ\0¿\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0!1A\"Qaq‘2R#¡±BÁÑbrS‚’¢3C$5ðá²%ñÒc4DÂTâsƒ£\0\0\0\0!1AQaq\"ð‘¡2R±ÁÑáB¢#ñb’3Scr‚C²ÒâòÿÚ\0 \0\0?\0ú¦€P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @(\0 €P @( Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 25, 2008 Share Posted June 25, 2008 Typically I see an INSERT commands that first list the field names and then the values. Your query is missing the field names: INSERT INTO images (field1, field2, field3, field4) VALUES ('739-736-444736.jpg', '80232', '.jpeg', 'ÿØÿà\0JFIF\0\0\0d\0d\0\0ÿì\0Ducky\0\0\0\0\0<\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0 Quote Link to comment Share on other sites More sharing options...
webent Posted June 25, 2008 Author Share Posted June 25, 2008 I've never done them that way, I've done them for the last 9 years this way, I don't think it makes a difference... FYI, I thought maybe the blob was perhaps too big for the mysql mediumblob, so I changed it to longblob, it didn't make a difference... Quote Link to comment Share on other sites More sharing options...
webent Posted June 25, 2008 Author Share Posted June 25, 2008 Nevermind, stupid mistake... I had $result for the query and $results for the error... 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.