Read picture dir and store pics to 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
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Read picture dir and store pics to Mysql

Post by Peuplarchie »

Good day to you all,
I was looking into makeing a database of all my image and I was wondering if there is a way to read a recursive directory and store it into the database.

I don't have a clue on how, even if I have search the web for a while.


Thanks, take care and have a good one !
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Read picture dir and store pics to Mysql

Post by Jonah Bron »

Sound's like you're looking for readdir(). With that, you can get all files in a given directory.
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Re: Read picture dir and store pics to Mysql

Post by Peuplarchie »

I know how to read or list a directory, what i don't know is how to put the result into the database.
The url or the whole image.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Read picture dir and store pics to Mysql

Post by Jonah Bron »

Something like this I should think...

Code: Select all

while (false !== ($file = readdir($handle))) {
    mysql_query('INSERT INTO sometable (url) VALUES ("'. mysql_real_escape_string($file) .'")');
}
You should never put the actual photo into a database. Store the URL.
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Re: Read picture dir and store pics to Mysql

Post by Peuplarchie »

what the (url) is for ?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Read picture dir and store pics to Mysql

Post by Christopher »

It is the name of the field in 'sometable' in which to insert the data.
(#10850)
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Re: Read picture dir and store pics to Mysql

Post by Peuplarchie »

Thanks!
Post Reply