#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    44
    Rep Power
    15
    I've noticed a number of questions on the board about storing images in databases. My question is this (hopefully it's a simple one)

    Can the actual jpg/gif image be stored as data in the database... or is it just a path to where the image is stored?

    If it can be stored as actual data.... how?

  2. #2
  3. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    From what I know about mySQL it is possible to store an image in a database under the BLOB (Binary Large OBject) datetype. However, the maximum size of your picture is limited to 65535 bytes. In order to get your picture into your database I presume you'd do something like this:

    <form action=POST enctype=multipart/form-data method=add.php3>
    <input type=file name=file>
    </form>

    ---ADD.PHP3---

    <?
    // Assume already connected to database
    insert into table values (
    $file
    );

    ?>

    That's how to get it in, assuming you have a table called test with one column that is a BLOB datatype: you'll have to use PHP or similar to view the image on a web page, which means that the image tag is going to be something like this:

    <img src="recall.php3?name=foo">

    which is a bit wierd!

    You also might run into problems here if your web host has set a maximum amount of table space that you can use. Whilst 10MB might seem ample for a database containing text, when you start to add pictures it will be used up very quickly! This is another reason why people use the image-copying way of doing it. Personally, when I'm adding records to a database, I'll use PHP to generate a random number, then that random number becomes the image name as well so there's no possibility of the file overwriting another on the server.

    ------------------------
    Alex Greg
    (http://www.alex-greg.co.uk)

    [This message has been edited by alexgreg (edited June 19, 2000).]

Similar Threads

  1. Stupid Access Question
    By slevytam in forum Database Management
    Replies: 4
    Last Post: February 22nd, 2003, 11:47 PM
  2. stupid question: what field type for storing sex?
    By .shapeShifter in forum MySQL Help
    Replies: 6
    Last Post: January 16th, 2003, 05:11 AM
  3. Replies: 1
    Last Post: December 17th, 2002, 04:00 AM
  4. stupid newbie question
    By joe_kralik in forum MySQL Help
    Replies: 1
    Last Post: November 13th, 2000, 05:56 PM
  5. stupid question...
    By evilsizord in forum PHP Development
    Replies: 1
    Last Post: August 30th, 1999, 05:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo