Pergunta

Possible Duplicate:
Storing Images in DB - Yea or Nay?
To Do or Not to Do: Store Images in a Database

I'm currently in the process of creating my friend's artist portfolio website. She asked me to create a simple system where she can upload an image and it will be displayed on the site according to the category it is in. I've stumbled upon several useful and interesting ways in which to achieve this and I've narrowed it down to the two that seem the most useful for me. Unfortunately, I do not know which one would be a better choice.

Option A: http://www.phpriot.com/articles/images-in-mysql

This method uses a very controversial way of storing images in a mySQL table using the blob datatype. I've read that it isn't recommended by many PHP programmers, however, it does seem like it can fit my needs perfectly. From what I understand it is fairly simple and easy:

  1. Upload Image to DB
  2. Display Image from DB according to category chosen.

Option B: http://webdeveloper.com/forum/showthread.php?t=101466

This method only shows how to upload an image to a directory using PHP. I figured once that is done I could make a simple list of all the images in that directory and put it into an array. Afterwards loop through the array and display those items in <img> tags.

So, you see, I am still learning how to work with PHP and mySQL and this website is great motivation to learn. However, I'm unsure of which method to use, or if there is a single method most web developers use?

Questions to Think About // TL;DR

  • What is the best method for uploading images that most of you use?
  • Would you consider using mySQL 'blob' datatype?
  • If uploading the image to a file directory is best, how would I display the images--using an array, placing the list of images in a DB, or something entirely different (because I'm a noob and don't know any better)

Thanks in advance for any replies!

Foi útil?

Solução

I wouldn't use database storage for large images, just upload them and write the file path/name and details into a database. Have a field in the database for Priority if you need to retrieve the images in a specific order

Just found Uploadify today, works great

Outras dicas

I use this on a project i'm working on and the way to go without having to write the files to disk is using a text column with the image as base64 string encoded data. The beauty of this is that you can output the file directly to browser via Data uri (info here: http://en.wikipedia.org/wiki/Data_URI_scheme).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top