hi everyone

i want to insert and retrieve images from the mysql using php(in wamp server).actually i searched the net and tried with many codes but cudnt find a solution.in the last one tht i tried,i created a table tht includes a blob datatype for one of its attribute and also an id that is auto incremented.i insert it normally using the insert statement.similarly for retrieving i assing the retrieved one to an <img src> but cudnt find anything working.then i opened the database and directly inserted an image to it.then while retrieving i cud see only a small icon like thing in the front end.when i tried to open it, i cudnt.can someone help me with this/
thanks in advance

Recommended Answers

All 2 Replies

hi josh.
thanks for ur reply.i tried that in my code.but there i redirected that to someothe page and retrieved the id there and got its value using 'get' function and there i selected the header type.here is my piece of code.ill try the code which u directed to me and let u know.
thanks

<?php
  include 'db.inc';

  $file = clean($file, 4);

  if (empty($file))
     exit;

  if (!($connection = @ mysql_pconnect($hostName,
                                       $username,
                                       $password)))
     showerror();

  if (!mysql_select_db("files", $connection))
     showerror();

  $query = "SELECT mimeType, fileContents FROM files 
            WHERE id = $file";

  if (!($result = @ mysql_query ($query,$connection)))
     showerror();  

  $data = @ mysql_fetch_array($result);

  if (!empty($data["fileContents"]))
  {

     header("Content-Type: {$data["mimeType"]}");

     echo $data["fileContents"];
   }
?>

i connected the database in db.inc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.