views:

65

answers:

6
+4  Q: 

php image upload

which is a better place to upload images to? A database or in the web directory? And why?

A: 

I don't think you can "upload" an image to a database. You can store the image's string value in the database and stream it via "header("Content-Type")" later on. That saves space in your web server, but obviously takes space on your database.

If I were you, I'd upload to a web directory, that way you have the image for a regular URL request later on. If you don't have it in a regular directory, you'll have to connect to the database every time the image is requested, and stream it then.

Raphael Caixeta
"image's string value" <- what is this? it's certainly possible to write the images binary data to a blob and recall it later.
Mark E
That's what I meant. Didn't know the correct term for it, my apologies.
Raphael Caixeta
+2  A: 

You should only store images in your database if you have a specific need to, like security, or like an absolute to-die-for need to keep all custom data in a database.

Other than that, getting large files into databases usually isn't worth the trouble. Storing and retrieving the file get that much more complicated to implement, and database updates/upgrades/conversions have that many more problems that can go wrong.

skoh-fley
A: 

Well It depends on your requirement. If you are considering security as a major issue then definitely you should store it in db other wise nothing will leads you to store images in db.

Also retieving images from database is quite complicated as in database images are stored as binary data. So if you have specific need then only store images in database other wise storing images in directory would be fine.

Dinesh Atoliya
+1  A: 

I don't see that there is an advantage storing images in a database. There is certainly no inherent security in this. Files are for the filesystem so store your images in there.

seengee
A: 

As you can see there are many reasons why to use/why not to use the database for image storage. Personally I prefer not to use the database for storage of files (images, documents etc), except when I'm ordered to store them.

-Sometimes you're tired and screw up a query, something like "SELECT * FROM images", this will kill the server if there are too many images with huge size (2MB and more) in the database. -The security issue: you can still save the files in the disk and still be secure, how? Well save the files outside the web directory, whenever the file is requested read the file and give it to the user. -If by any chance you are using MySQL: if your database has got to big (say 2-3 GB), and you are using a shared hosting, well good luck making that backup or trying to restore that image database.

It's just my point of view

Flakron Bytyqi
A: 

thanks everyone!

Ohnegott