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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to display images in PHP

Reply to Message Icon

Name: rsasalm
Date: September 23, 2005 at 12:50:54 Pacific
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>



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: how to display images in PHP

how to use filedsn in php www.computing.net/answers/webdevel/how-to-use-filedsn-in-php-/3640.html

How to send mail in php localhost www.computing.net/answers/webdevel/how-to-send-mail-in-php-localhost/3919.html

Animating images in PHP www.computing.net/answers/webdevel/animating-images-in-php/2268.html