locked
How to store the images in the Mysql database and also fetch and display on PHP form ??? RRS feed

  • Question

  • Help Me

     

    I want to store the images in the Mysql database and also fetch and display on PHP form.

    I tried in the following code but i dont know about properly that code is right or wrong.

    If any other method there then plz help me about this procedure........

     

    I also mention that how to create table and upload the image with my view.

     

    Opposite of how you stored it (more or less). This is a sample:

    Code: ( php )To fetch  the image

    --------------------------------------------------------------------------------------------------------------------
    $sql    = "SELECT * FROM image WHERE image_id='image_id'";
    $result = mysql_query ($sql, $conn);
    if (mysql_num_rows ($result)>0) {
      $row = @mysql_fetch_array ($result);
      $image_type = $row["image_type"];
      $image = $row["image"];
      Header ("Content-type: $image_type");
      print $image;
    }

     

    --------------------------------------------------------------------------------------------------------------------

    CREATE TABLE Images (
    PicNum int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Image BLOB
    ); 

    Setting the upload script

    <?
    If($Picture != "none") {
    $PSize = filesize($Picture);
    $mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize));
    mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
    @mysql_select_db($db) or die("Unable to select database");
    mysql_query("INSERT INTO Images (Image) VALUES ('$mysqlPicture')") or die("Can't Perform Query");
    }
    else {
    echo"You did not upload any picture";
    }
    ?>
     

    Thursday, December 6, 2007 9:34 PM