cool_techie Posted January 30, 2011 Share Posted January 30, 2011 I am unable to upload image to db, I get a message "No image selected/uploaded" after every trial, My HTML form is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form enctype="multipart/form-data" action="insert.php" method="post"> <input name="image" accept="image/jpeg" type="file"> <input value="Submit" type="submit"> </form> </body> </html> and my php script "insert.php" is- <?php // Create MySQL login values and // set them to your login information. $username = "root"; $password = ""; $host = "localhost"; $database = "test"; // Make the connect to MySQL or die // and display an error. $link = mysql_connect($host, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } // Select your database mysql_select_db ($database); // Make sure the user actually // selected and uploaded a file if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { // 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); // Create the query and insert // into our database. $query = "INSERT INTO tbl_images "; $query .= "(image) VALUES ('$data')"; $results = mysql_query($query, $link); // Print results print "Thank you, your file has been uploaded."; }else{ print "No image selected/uploaded"; } // Close our MySQL Link mysql_close($link); ?> my table consists if an "id" and an "image" of type "blob". Link to comment https://forums.phpfreaks.com/topic/226129-unable-to-upload-image-to-a-database/ Share on other sites More sharing options...
sunfighter Posted January 30, 2011 Share Posted January 30, 2011 My advice is "don't put images into a database. Save and use them from a file. Put the image name into the database." But if you really want to do this: I would first find out if I'm uploading the image. Put it into a folder and see if that is working. Then go here and read the last entry "MySQL Image Table" -> http://hockinson.com/ Link to comment https://forums.phpfreaks.com/topic/226129-unable-to-upload-image-to-a-database/#findComment-1167390 Share on other sites More sharing options...
cool_techie Posted February 2, 2011 Author Share Posted February 2, 2011 can u provide me with some links wherein i can find some good stuff about working with files....? Link to comment https://forums.phpfreaks.com/topic/226129-unable-to-upload-image-to-a-database/#findComment-1168822 Share on other sites More sharing options...
sunfighter Posted February 3, 2011 Share Posted February 3, 2011 http://us3.php.net/manual/en/function.fopen.php and most of the links on the left side Link to comment https://forums.phpfreaks.com/topic/226129-unable-to-upload-image-to-a-database/#findComment-1169246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.