Page 1 of 1
how to create a database that will add an image?
Posted: Thu Apr 17, 2008 5:20 am
by rjuy
can u pls help me, i kept on searching on how to add an image into the database but i haven't found a image data type.......
so how can i add an image in my database if there is no image datatype,
pls help me guys..........
thanks..............
Re: how to create a database that will add an image?
Posted: Thu Apr 17, 2008 5:34 am
by aceconcepts
What you would do is add the image name (including extension) to the database and upload the actual image file to a directory on your server.
When you need to display the image simply use the directory path of where the images is stored and reference the name of the file from the database.
Re: how to create a database that will add an image?
Posted: Thu Apr 17, 2008 5:36 am
by m4rv5
google is your best friend
http://www.google.com.sg/search?q=mysql ... =firefox-a
This article basically covers also what you need. But the difference from what ace suggested is that this stores the binary file itself onto the database .
http://www.phpriot.com/articles/images-in-mysql
Re: how to create a database that will add an image?
Posted: Thu Apr 17, 2008 5:36 am
by onion2k
Images are binary data ... so use a BLOB (binary large object) data type.
It's not really a good idea though. Files shouldn't be stored in the database except under very specific and unusual circumstances. If they're in the database you need to open a connection, stream the binary data out to a script which holds it in memory, then stream that out to the user. It's really inefficient compared to just storing the filename and having your script fetch the file from the file system instead.
Re: how to create a database that will add an image?
Posted: Thu Apr 17, 2008 1:00 pm
by mabus
I would strongly suggest saving the filename of the image to the database, instead of using blob. It will cost you less overhead on your db.
However, there are things that you will need to consider with the filenames. Here are among some of them..
1. You need a place to store the files, and such directory should be manageable enought. I don't think it is a good idea to include the whole path in your database entry, but you should manipulate this from your php scripts.
2. Filenames should be unique to avod overwritting. One solution is to use UUID, or encrypt the filename, or make string manipulations to the filename.
There will be a lot more, but you shall tackle them when you write your app.
Re: how to create a database that will add an image?
Posted: Fri Apr 18, 2008 3:16 am
by aceconcepts
To prevent overwriting a file in your directory you could always use
http://uk3.php.net/function.file-exists
Re: how to create a database that will add an image?
Posted: Wed Dec 10, 2008 10:33 am
by rjuy
thanks you guys
-rjuy