7 Years
Discussion Span
Last Post by metalix

I'm no expert here but I've read loads on whether it is better to store the image in the file system or in the database, opinion seems to be divided and you could spend a lifetime reading through all documents trying to make an opinion for yourself.

For my solutions I store the image in the file system and a url to the image in the database.

I have a simple table with 3 columns
1 id INT
3 desc VARCHAR

then from a form with 3 fields I upload images to the file system and add the path and description to the database.

1 input=file name=pic
2 input=text name=desc

once the image has been chosen (from local, server or remote) and a name added I post to a php script

the php constructs the image path and moves the image to the file system (local, server or remote)

something like

$target_path = "foldername/";
$path_builder1="<img src=";
$pic= $_FILES['pic']['name'];

$target_path = $target_path. basename( $_FILES['pic']['name']); 

if(move_uploaded_file($_FILES['pic']['tmp_name'], $target_path)) {

the last step is to add the image description and path to the database

$sqla="INSERT INTO table (desc, url) VALUES ('$desc','$url')";

Edited by Ezzaral: Fixed code tags.


If you want to use the image across severl domains it is better to store in a database via binary, but you will need to check with your hosting provider if its ok.
also it helps to put a size limit on the upload. say 100kB which allows for a medium good quality image about 600px wide after compression
I will post a tutorial on mysql image processing when I have time

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.