Images/PHP and MySql? How does it work?

Hi Everyone,

I’m not entirely sure how images would work with php. The images these types of websites have (below) do you believe the images are stored in a mysql database and called like everything else or are they stored differently? If so, how are they called?

<snip>picture of a car</snip>
<snip>picture of a truck</snip>

Thanks Everyone!

Hi scm22ri,

The recommended method of storing images in the database is to have your images located on your web-folder - say a path might be /var/www/my_site_folder/catalogue_images/.

You then store any uploaded automobile images in the catalogue folder and you store the web path in the database, so let say your domain is [noparse][/noparse] then you would loop through or select a model of car (in the database) and grab its’ image name and then using php append the path together.

$image_path = "./catalogue_images/$my_selected_image_name_from_the_db";

then where you need to display it:

$image = "<img src='$image_path' alt='$my_short_description_from_the_db' />

Hope this helps.


Thank you Steve. That was helpful.

We can also store the images in mysql database by converting them into binary data and then we have to make our database table image field “blob” type. and the image is stored but that is not better option. ServerStorm has answered correct.