Upload files for a specific folder and store them in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

Upload files for a specific folder and store them in mysql

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

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

Post 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.
funkyapache
Forum Newbie
Posts: 11
Joined: Tue Mar 24, 2009 11:19 am

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

Post 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.
Post Reply