Jump to content

Images/PHP and MySql? How does it work?


scm22ri

Recommended Posts

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/vehicleinfo/02921/all/all/0/999999/0/999999/5YMGY0C52CLK27716/yy0115/

 

Thanks Everyone!

Link to comment
Share on other sites

To be honest, it's really hard to tell how the images are stored. They could be stored as files that are directly accessed, or they could be stored as files that are indirectly accessed through a script, or they could be stored in a database as a 'blob' (binary large object) and accessed through a script. Your browser can't tell the difference, so it's hard to tell what process was used.

 

If you have done everything correctly, it shouldn't matter how you have stored the images. I usually store the files in a locked directory so that they can't be accessed directly, then I use a PHP script to fetch the files. The only thing I store in the database is details about the file (height, width, original file name, etc.) and I don't store the files by their original name, that way I can guarantee that each file is uniquely named and doesn't overwrite other files.

Link to comment
Share on other sites

There's no way to tell from viewing a website how they handle images. There are several approaches. Here are a few:

 

1. In the database, store the Path and Name (or just name if all files are in the same directory) of the image which is stored on the server (or accessible to the server). Then when displaying information about the product you use that path/name to create an image tag using that path in the src attribute.

 

2. Actually store the image data in the database. This requires you to read all that data and create an image to return to the client. I think you can include the image directly in the HTML file, but it would be messy. A more common approach is to create an image tag as above and use a PHP file as the source with the image ID as a parameter. The PHP page would look up the image in the database and create the image to return to the HTML page.

 

3. Or you can just name the images using the ID of the record. So, if you have record with id 123456, just name the photo 123456.jpg. Then when displaying the record details you use the id to grammatically set the image name in the IMG tag. If you will ALWAYS have a one-to-one relationship between the record and the image, this will suffice. but I personally don't like it.

 

My preference is #1. Storing images in the database is more overhead and is not worth the effort. There are a few narrow uses cases where it might make sense. but, they are few and far between.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.