Page 1 of 1

Images/PHP and MySql? How does it work?

Posted: Tue Aug 28, 2012 1:59 pm
by mcc_shane
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?

http://www.lotpro.com/cars/new/porsche/boxster/
http://www.lotpro.com/search/vehicleinf ... 16/yy0115/

Thanks Everyone!

Re: Images/PHP and MySql? How does it work?

Posted: Tue Aug 28, 2012 4:16 pm
by social_experiment
It's preferable to not store files in a database;
mcc_shane wrote: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?
Images could be stored inside the root (or outside) folder and then accessed "normally" like giving a value to an <img > tag.

Re: Images/PHP and MySql? How does it work?

Posted: Wed Aug 29, 2012 2:24 pm
by califdon
Just to elaborate on social_experiment's reply, it's impossible to tell how something is stored if the html is created with php code, since all you can see in the source code is the html that was generated by php. That's the real point: it makes no difference to the browser where the image is located, since it's the web server that has to retrieve it and incorporate it into the data sent to the browser. The reason for recommending storing just the path to the image in the database is based on database performance. It probably doesn't make much difference if it's only a few images and if you don't expect to hardly ever change the images (requiring database maintenance), but storing images directly in a database would introduce complexities in maintaining the database later on if images had to be added, deleted or changed, and perhaps cause performance issues if there were many thousands of images. So it's just a good habit to form, to store the images separately and store the paths to them in the database.