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 !
Read picture dir and store pics to Mysql
Moderator: General Moderators
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
- 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
Sound's like you're looking for readdir(). With that, you can get all files in a given directory.
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
Re: Read picture dir and store pics to Mysql
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.
The url or the whole image.
- 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
Something like this I should think...
You should never put the actual photo into a database. Store the URL.
Code: Select all
while (false !== ($file = readdir($handle))) {
mysql_query('INSERT INTO sometable (url) VALUES ("'. mysql_real_escape_string($file) .'")');
}- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm
Re: Read picture dir and store pics to Mysql
what the (url) is for ?
- 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
It is the name of the field in 'sometable' in which to insert the data.
(#10850)
- Peuplarchie
- Forum Contributor
- Posts: 148
- Joined: Sat Feb 04, 2006 10:49 pm