rene.miller3 Posted July 19, 2011 Share Posted July 19, 2011 Hello I am new to this forum and would greatly appreciate any help. I am trying to display a BLOB from my database onto a webpage, but I have no clue how to do this. My current code displays the name of the BLOB, not the BLOB itself. Here is the code: <html> <?php $con = mysql_connect("mysql17.000webhost.com","a2870045_r ayman3","hawaii" ); mysql_select_db("a2870045_picture", $con); $result = mysql_query("SELECT * FROM Art ORDER BY RAND() LIMIT 1"); $row= mysql_fetch_array($result); $file = $row["File"]; mysql_close($con); ?> <center><?=$file?></center> </html> Again, any help would be appreciated. If you need clarification, please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/ Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 1. please don't display your mysql information on here...this is sensitive data.. 2. Instead of storing blobs inside of a database..which in my opinion is the harder/less inefficient way to do this...what I would recommend is that you store the image(s) inside of a directory, store the image path inside of your database, then use that as your img source.. Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1244720 Share on other sites More sharing options...
rene.miller3 Posted July 19, 2011 Author Share Posted July 19, 2011 I changed the mysql information, none of what is posted in this forum is actually correct. Alright I will try that. Thanks much for the help. Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1244722 Share on other sites More sharing options...
srikanth03565 Posted July 19, 2011 Share Posted July 19, 2011 Hi, If u want to display data in blob first write that data to a file then refer that file in your current context write to a image file then in your image path specify that path <img src="path" alt="PHP-generated image"> Other wise echo that field in a php file like image.php header("content-type:image/png"); echo $field; then point that action to your image i.e <img src="image.php?id=1" alt="PHP-generated image"> Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1244728 Share on other sites More sharing options...
rene.miller3 Posted July 19, 2011 Author Share Posted July 19, 2011 AyKay47, can you share a little more guidance on how to store the image to a directory? I think your solution will work perfectly for what I'm trying to do. I'm very new to PHP, and I greatly appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1244731 Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 AyKay47, can you share a little more guidance on how to store the image to a directory? I think your solution will work perfectly for what I'm trying to do. I'm very new to PHP, and I greatly appreciate your help. okay here we go..say you have a folder that you will store your images in named "images" located under the root directory..."http://host.com/images" Okay now say you uploaded a picture into the "images" directory named "test.jpg" What you would insert into the database field where your image paths are stored is "/images/test.jpg" Then when you are ready to extract that image path you would do something like this.. $query = mysql_query("SELECT image_path FROM table_name WHERE something = 'something'"); //insert correct table/field names $row = mysql_fetch_array($query, MYSQL_ASSOC); $image_path = $row['image_path']; print "<img src='$image_path' />"; If you want to display more then one image, use a while loop... Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1244735 Share on other sites More sharing options...
rene.miller3 Posted July 20, 2011 Author Share Posted July 20, 2011 Okay so even more basic than that, how do you post pictures to a directory? Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1245312 Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 you will need a form with the enctype set to "multipart/form-data" with an input type of "file" so.. <form method="POST" action="#" enctype="multipart/form-data"> <input name="image" type="file" /> </form> you will grab this file with the $_FILES array instead of the $_POST array here.. then you will move the uploaded to file to a directory of your choosing using move_uploaded_file and store that file path into your db Quote Link to comment https://forums.phpfreaks.com/topic/242348-displaying-blob-from-database/#findComment-1245338 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.