Database Articles

  Home arrow Database Articles arrow Page 4 - Storing Images in Database
DATABASE ARTICLES

Storing Images in Database
By: Hermawan Haryanto
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 62
    2002-12-29

    Table of Contents:
  • Storing Images in Database
  • Database Preparation
  • Start Coding
  • Viewing the Images
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Storing Images in Database - Viewing the Images


    (Page 4 of 5 )

    Now, after you upload your image to the database, what's next? Of course we need a way to display it to users. Here is the script to retrieve image information from database then displaying to the users.

    <?php
    // image.php - by Hermawan Haryanto &lt;hermawan@dmonster.com&gt;
    // Example PHP Script, demonstrating Storing Image in Database
    // Detailed Information can be found at http://www.codewalkers.com

    // database connection
    $conn = mysql_connect("localhost", "user", "password") 
      OR DIE (mysql_error());
    @mysql_select_db ("hermawan", $conn) OR DIE (mysql_error());
    $sql    = "SELECT * FROM image WHERE image_id=".$_GET["iid"];
    $result = mysql_query ($sql, $conn);
    if (mysql_num_rows ($result)&gt;0) {
      $row = @mysql_fetch_array ($result);
      $image_type = $row["image_type"];
      $image = $row["image"];
      Header ("Content-type: $image_type");
      print $image;
    }
    ?>

    Example, you have image with ID = 3, then you should call that file using this method <img src='image.php?iid=3'>. It's simple right? On the index.php, I've been add a link to display the page on the file, which print out an HTML tag to display the image.php file, take a re-look at index.php.

    More Database Articles Articles
    More By Hermawan Haryanto

    blog comments powered by Disqus

    DATABASE ARTICLES ARTICLES

    - Completing a Book Inventory Management System
    - Uploading Images for a Book Inventory Manage...
    - Finishing the Add Book Story for a Book Inve...
    - Integration Testing for a Book Inventory Man...
    - User Stories for a Book Inventory Management...
    - Unit Testing a Book Inventory Management Sys...
    - Testing a Book Inventory Management System
    - Implementing Models for a Book Inventory Man...
    - Book Inventory Application: Publishers and B...
    - Handling Publishers in a Book Inventory Mana...
    - Publisher Administration for Book Inventory ...
    - Book Inventory Management
    - Using the SQL Reference Manual
    - Using Oracle SQL Developer with SQL Statemen...
    - Fixing Errors with Oracle SQL Developer


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap