Computing.Net > Forums > Web Development > how to display images in PHP

how to display images in PHP

Reply to Message Icon

Original Message
Name: rsasalm
Date: September 23, 2005 at 12:50:54 Pacific
Subject: how to display images in PHP
OS: WinXP
CPU/Ram: P4
Comment:

Hi all,
I am new to this group and PHP programming.
I have a very simple question.
I have a database where I want to store and display all images.
I have inserted few images in the database and now I want to display all of them.

I get only one image display and not all.
If I try to change the code line in for-loop
echo $bytes[$x]."

";

with
echo '

';
no image is displayed.


*********************************************

file name: insert_complete.php


<?php
$productName=$_POST[productName];
$productPrice=$_POST[productPrice];
//$imagefile=$_POST[imagefile];
$imagefile=$_POST[imagefile];
$whatsit=$_POST[whatsit];
// Connect to database

$errmsg = "";
if (! @mysql_connect("localhost","root","")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("dummy");

if ($_REQUEST[completed] == 1) {
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")))

if (strlen($instr) < 149000) {
echo "Inside Inser";
$sql = "INSERT INTO pix ";
$sql .= "(productName, producPrice, title, imgdata) ";
$sql .= "VALUES ('$productName', '$productPrice', '$whatsit','$image')";
mysql_query($sql);


} else {
$errmsg = "Too large!";
}

while ($row = @mysql_fetch_assoc($gotten)) {
$pName = htmlspecialchars($row[productName]);
$pPrice = htmlspecialchars($row[producPrice]);
$title = htmlspecialchars($row[title]);
$bytes[] = $row[imgdata];
}

if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");

for ($x=0; $x < count($bytes); $x++){
echo $bytes[$x]."

";
//echo '

';
}
exit ();
}


<html><head>
<title>Insert Complete</title>
<body bgcolor=white><h2>Here's the latest picture</h2>
<?= $errmsg ?>
<center><?php require 'insert_complete.php?gim=1'; ?>

<?= $title ?></center>
<hr>
<h2>Upload a new product to Database.</h2>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=150000>
<input type=hidden name=completed value=1>

Product Name: <input type="text" name="productName">

Product Price: <input type="text" name="productPrice">

Please choose an image to upload: <input type=file name=imagefile>

Please enter the title of that picture: <input name=whatsit>

then: <input type=submit></form>


</body>
</html>


Report Offensive Message For Removal








Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: how to display images in PHP 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge