I have pictures stored in a database, when I will see them I get only
placeholder of pictures but not the picture self. What is wrong in my code?
Please help me.

Code section:

1) PHP-HTML for storing:

if (!isset($img1)) {
   header("Location: http://localhost/php/insert_file.html";);

$db = mysql_connect() or die("Can't connect to server.");
mysql_select_db("media", $db) or die("Can't select database.");

$binary_junk = addslashes(fread(fopen($img1, "r"), filesize($img1)));

$insert_data = "INSERT INTO images(img_id, binary_junk, filename, filesize,
filetype) VALUES ('4', '$binary_junk', '$img1_name', '$img1_size',

mysql_query($insert_data) or die("Couldn't insert data.");


<TITLE>Successful File Insertion!</TITLE>

<P>You have inserted the following into your database:<br>
<? echo "$img1_name"; ?>, a <? echo "$img1_size"; ?>  byte file with a mime
type of <? echo "$img1_type"; ?>.</P>


2) Html for viewing:


<H1>Look at this:</H1>
<IMG SRC="show_image2.php">

3) PHP for viewing:

 $db = mysql_connect();

 $sqlab = "select img_id, filename, binary_junk, filetype from images";

 $res = mysql_db_query("media", $sqlab);
 $num = mysql_num_rows($res);

 if ($num==0)
 echo "Leider wurden keine Bilder gefunden<br>";

 for($i=0; $i<$num; $i++)

  $id = mysql_result($res, $i, "img_id");
  $fn = mysql_result($res, $i, "filename");
  $ft = mysql_result($res, $i, "filetype");
  $bj = mysql_result($res, $i, "binary_junk");

  header("Content-type: $ft");
  echo "$bj" . "<p>";




Thanks for your help.


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to