Page 1 of 1
Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 4:56 pm
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 !
Re: Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 6:44 pm
by Jonah Bron
Sound's like you're looking for
readdir(). With that, you can get all files in a given directory.
Re: Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 6:58 pm
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.
Re: Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 9:20 pm
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.
Re: Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 9:45 pm
by Peuplarchie
what the (url) is for ?
Re: Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 9:49 pm
by Christopher
It is the name of the field in 'sometable' in which to insert the data.
Re: Read picture dir and store pics to Mysql
Posted: Mon May 24, 2010 10:03 pm
by Peuplarchie
Thanks!