Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.databases.mysql Subject: Re: Can MySql database store images? Date: Sun, 24 Apr 2011 09:23:32 +0200 Lines: 41 Message-ID: <91i1fkFetdU1@mid.individual.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net AjYQKWl8+G2aNE1SGOEd9wLaPOnw4TRbIOH7miW6fdvgX7THro Cancel-Lock: sha1:domsl9SoogKKjNGL2b8vPvebTW8= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.17) Gecko/20110306 Gentoo/2.0.12 SeaMonkey/2.0.12 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.databases.mysql:597 Robert Crandal wrote: > I am planning to allow each user to upload as many photos as > they want into their personal account space, but my problem is > that I don't know WHERE to store an unknown number of images > in each user account. Can I store a collection of images in the > MySql database somewhere? How? Also, what are some other > ways to do this? There are different ways you can do this, the more traditional way would be to have a directory where you create one directory per user (say the user name) and then store that users images there. You could also store the images in a database table CREATE TABLE userimages( id int unsigned auto_increment primary key, userid int unsigned not null, name varchar(120) not null, comment text, image blob not null ); The trickier part will be displaying the image, as you will need to have some kind of script which fetches the image from the database and outputs the raw data. I would recommend that the script fetches based on the id of the image, it may include access checks too (if you want to allow the user to set different access modes on images like "private", "public", "friend only"). If you are using a web hotel, then you may prefer to do the first option to store directly to the disk, as you usually will have a lot less space to use for your database than for your other files. Keep in mind, don't do any "SELECT * FROM userimages" as you will fetch all the image data too, if you want to create a list, then just use "SELECT id, userid, name, comment FROM userimages", this will be lighter for your page, specially if you have loads of images stored in the database. -- //Aho