How to insert pictures in database

Posted on 2005-04-08
Last Modified: 2008-03-04
I have list of cars and i want to stick 3 serperate pictures for each car. Im just wondering how would i go about storing them in database and also how to retrieve them from the database on display them on page

I have three pics called image1, image2, and image3 and i have them stored in folder called c:\opensa\apache\htdocs\HBC\images2
Question by:acslater
    LVL 12

    Assisted Solution


    This is a very popular question:

    Have a look at this PAQ

    http:Q_21205707.html - MySQL image placeholder

    Hope this helps :)

    Author Comment

    Do i store the path to the picture in mysql. for example would iput in c:\opensa\apache\htdocs\HBC\images2\image1 in the database as a value
    LVL 7

    Expert Comment

    Basically if you're storing filenames in your database, the database's usefulness is only in knowing where to find each image file.  You wouldn't want to write an absolute reference to the images like "c:\\opensa\\apache\\htdocs\\" etc...  This will limit your options should you ever have to move your system to a linux machine, or another directory on your windows machine.  Just reference each file relative to the main image directory on your web system...

    The trick with these filebased database systems is keeping an orderly filesystem for all your images.  Often it's helpful to name images or image subdirectories after SQL ids for each item (each car's ID, in this case).
    LVL 20

    Expert Comment

    storing the path is the far preferred solution.  And systemizing the paths as minnirok suggests is also a helpful detail.

    storing images themselves in the DB doesn't really get any DB benefits.   This is because the DB stores them as BINARY BLOBs, not the most friendly data type, since all your storing is really a file.  You don't get any search benefits from this.


    Author Comment

    i have read the previous examples but dont fully understand. So i have just manually put the picture into the database. The name of the field in the database is called people and the image is called image1. I have put in c:\opensa\apache\htdocs\HBC\images2\image1 for each field.

    Could anyone show me code just to view this image? its hardly as easy as:
    <? echo $row["people"]; ?>.gif

    LVL 32

    Accepted Solution


    Author Comment

    yes got them to show tanks lads. how can i split the points because ye all helped out
    LVL 4

    Expert Comment

    Hi acslater,

    Check out the instructions on how to split the points here


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now