1

I have a folder with full of images.But I have to upload the images to mysql database.

How can I do it using php code?

Regards,
Rekha

shamittomar
  • 46,210
  • 12
  • 74
  • 78
Rekha
  • 449
  • 2
  • 15
  • 27
  • 1
    Maybe read first: [Storing Images in DB - Yea or Nay?](http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay) – Pekka Sep 08 '10 at 11:14
  • 1
    Almost duplicate: http://stackoverflow.com/questions/1047547/correct-way-to-upload-image-to-database – Pekka Sep 08 '10 at 11:14

2 Answers2

0

It's usually not a good idea to do this. Read the discussion I linked to in the comment.

But to answer your question, here is what seems to be a pretty complete tutorial showing how to store images in a mySQL database.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

I am not store image in DB. It is a bad practice. If we have a some ID, we rename images as image$ID.ext. If we haven't ID, we write in DB only a filename. If you want to write in database all filenames of dir, try to use this code:

function getDirectoryList ($directory) {
   $results = array();
   $handler = opendir($directory);
   while ($file = readdir($handler)) {
      if ($file != "." && $file != "..") {
         $results[] = $file;
      }
   }
   closedir($handler);
   return $results;
}
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143