1

A friend of mine told me that saving images in the database is not much of a good idea. Instead save it to the directory and then save it's name in the database and when I want to display the images in the browser I'm just going to use the name in the database to find the picture. Can anyone please guide me on how to do this starting from scratch? Any help would be much appreciated.

By the way I am using php and MySQL.

Jakub Hampl
  • 39,863
  • 10
  • 77
  • 106
zerey
  • 871
  • 11
  • 19
  • 37
  • 5
    Accept some answers to get some more :) – Ivan Ivanic Mar 18 '11 at 20:25
  • This is too broad. Please ask a specific question. See also: [Storing Images in DB - Yea or Nay?](http://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay), [Save image in database?](http://stackoverflow.com/questions/805519/save-image-in-database). – outis Mar 18 '11 at 20:27
  • I think there is nothing inherently wrong with storing files in a database. Securing and managing it properly becomes way easier. What volume are you looking at? – mvds Mar 18 '11 at 20:29
  • @mvds - at present we only have stored several images.. but thinking ahead of time gives me the idea that in the future there are thousands of images to be saved.. because the database will be used to store multiple informations including pictures of students on a university. – zerey Mar 18 '11 at 20:35
  • @outis - how do you store image locations on the database and call them when you need to display them on the page. – zerey Mar 18 '11 at 20:36
  • @zerey: edit your question to make it more specific, rather than posting a comment. – outis Mar 18 '11 at 20:40
  • @zerey - at such scales the overhead of maintaining synchronisation between a filesystem and a database may be worth it. But be warned that you are adding a whole new layer to your design - e.g. suppose you are to implement mysql replication, then you also need to implement your own replication for your filesystem based files. Ditto when making backups, restoring backups, when migrating to another server, ... – mvds Mar 18 '11 at 20:45

2 Answers2

3

Do two things:

Community
  • 1
  • 1
ChrisR
  • 14,370
  • 16
  • 70
  • 107
1

What is it exactly that you don't know how to do? Your question seems to contain its own answer:

  1. set up a directory for images, accessible to your web server
  2. copy some image files in there
  3. go to phpmyadmin and create a table with a filename field, for example of type varchar 100
  4. store the image filenames in the table
  5. write a php script that fetches image names and displays the HTML to load the images
Jakob
  • 11
  • 1