l0ve2hat3 Posted April 15, 2008 Share Posted April 15, 2008 I have pictures already uploaded in a folder in a server. What I need to do is convert the files to store them in a mysql database. could I use file_get_contents to do this? Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 15, 2008 Share Posted April 15, 2008 what you do is store the names in your database and then use a mysql_query() to get the names from your database then just echo something like this: $query = mysql_query("SELECT * FROM images"); while($image = mysql_fetch_object($query)){ echo "<img src='/folder/". $image->name ."' />"; } Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted April 15, 2008 Share Posted April 15, 2008 Its difficult to store image files in the MySQL database. Instead just save the url of the image and retrive it as Northen Flame directed in above post. Quote Link to comment Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 From what I understand, this is a bad idea. It's possible to do it, but not at all the best way to manage images. Use the above suggestion about storing just the filename/path. Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted April 15, 2008 Share Posted April 15, 2008 There is one alternative to the above mentioned ideas.You can make the database field to hold BLOB rather than varchar and when u store the image in the database it will be stored in binary format.There are many tutorials online about storing BLOB object in database,why dont u try one? Quote Link to comment Share on other sites More sharing options...
gdfhghjdfghgfhf Posted April 15, 2008 Share Posted April 15, 2008 yep i just went through one of these tutorials about storing images in mysql in BLOB format i also saw a script that will do exactly what you want: take all images you have in a folder and put them in database just search on google with revealent keywords and you will find it Quote Link to comment Share on other sites More sharing options...
benphp Posted April 15, 2008 Share Posted April 15, 2008 I'm still not sure why you would want to store the images IN the database. There must be a reason, but I can't think of one. If you do, and your images are large, or there are a lot of them, you're asking for trouble. 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.