Page 1 of 1

Upload files for a specific folder and store them in mysql

Posted: Tue Mar 24, 2009 11:30 am
by funkyapache
Hi

I have about 4 gigs worth of pictures. I would like to store these in a mysql table to use on my website.

I know you can store images in a mysql table as a BLOB. I have the following questions:

1. How do I fetch a list of files on my server in a specific folder and loop them them?
2. can I remove them once inserted into mysql table?

Any help much appreciated and I am still a php newbie so please excuse some of my silly questions.

Re: Upload files for a specific folder and store them in mysql

Posted: Tue Mar 24, 2009 6:13 pm
by Ambush Commander
How do I fetch a list of files on my server in a specific folder and loop them them?
scandir() if you're on PHP5; glob() also works well.
can I remove them once inserted into mysql table?
unlink(). I'd be careful about doing that until you're sure you know how to get the images back out of MySQL.

Why do you want to store images in the database? Most modern web applications keep them in the filesystem for performance reasons.

Re: Upload files for a specific folder and store them in mysql

Posted: Wed Mar 25, 2009 4:21 am
by funkyapache
Hi Ambush,

Thanks for the reply, I'll do some reading up on those two functions.

I was hoping to make my website self contained and was hoping to just backup the db rather than the db and the system files. I thought it would be difficult to link all my pictures in different directorys but your suggestion did get me thinking and I surpose I could create a php function that would create a list of files and directories and loop through them and for each picture insert a reference (i.e the files path in the filesystem) into the table and then just pull out the href/path from the table and place it onto the page in a img tag.

I'll let you know how I get on.