I found this worked fine for me, I used the same method to read the file
into the database and the following lines to print the image out.
I tested this with images from 1kb --> 945kb both gif/jpg and it worked
fine
<?
$conn = mysql_connect("x", "x", "x");
$db = mysql_select_db ("img");
$result = mysql_query ("select * from img");
$image = mysql_result($result, 0, "image");
mysql_close($conn);
echo $image;
?>
Try taking out your header statements in display.php just to see what
happens. Also, you script doesn't timeout half way through does it ?
(wild guessing now) Does your web server show anything in the logs ?
Gareth
-----Original Message-----
From: Michael Hall [mailto:[EMAIL PROTECTED]]
Sent: 07 December 2001 14:08
To: phantom
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Uploaded Image display problems
I can't help you with the problem described below, but I can tell you
this:
I, like many others, do not store images as BLOBs in a database. I store
them in a regular directory (/images), and just store the image name,
path
or URL in the database. This generally creates less hassles.
Mick
On Fri, 7 Dec 2001, phantom wrote:
> With thanks to you who have helped me, I have constructed a PHP script
> that allows the client to upload an image (jpg or gif) that is stored
in
> a MySQL Blob field.
>
> And I have a PHP script that will pull the binary data out of the
MySQL
> database and display the upload image for the client.
>
> THE PROBLEM: HALF MY GIF AND JPG FILES DO NOT DISPLAY PROPERLY WHEN
> VIEWING THE DISPLAY.PHP SCRIPT (see below). Half display fine, half
do
> not.
>
> Has anyone else had this problem or know what I can do to remedy it?
> Thank you.
>
> Source code below * form.htm, insert.php, display.php *
>
> ============ FORM HTM =============
>
> <HTML>
> <HEAD>
> <TITLE>Insert Binary Data in a Database</TITLE>
> </HEAD>
>
> <BODY>
> <H1>Upload a File:</H1>
>
> <FORM enctype="multipart/form-data" method="post" action="insert.php">
> <input type="hidden" name="MAX_FILE_SIZE" value="200000">
> <INPUT type="file" name="img1" size="30">
> <br><br>
> <INPUT type="submit" name="submit" value="Use This File">
>
> </FORM>
> </BODY>
> </HTML>
>
> ============ INSERT PHP =============
>
> <?
> if (!isset($img1)) {
> header("Location: insert_file.htm?Msg=EmptyUpload");
> exit();
> }
>
> $db = mysql_connect("localhost", $DB_Username, $DB_pass)
> or die ("Unable to connect to server.");
> mysql_select_db($DB_name)
> or die ("Unable to select DB");
>
> $binary_junk = mysql_escape_string(fread(fopen($img1, "r"),
> filesize($img1)));
> // original file used addslashes but here I used mysql_escape_string;
>
> $insert_data = "INSERT INTO ImageTable
(ImgName,ImgSize,ImgType,ImgData)
> VALUES ('$img1_name', '$img1_size', '$img1_type', '$binary_junk')";
>
> mysql_query($insert_data)
> or die ("Unable to insert data: ".mysql_error());
>
> $PKey = mysql_insert_id();
>
> ?>
>
> <HTML>
> <HEAD>
> <TITLE>Successful File Insertion!</TITLE>
>
> <H1>Success!</H1>
>
> <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>
> View Your Image <a href="display.php?PKey=<?=$PKey?>">HERE</a>
> </BODY>
> </HTML>
>
> ============ DISPLAY PHP =============
>
> <?
> $db = mysql_connect("localhost", $DB_Username, $DB_pass)
> or die ("Unable to connect to server.");
> mysql_select_db($DB_name)
> or die ("Unable to select DB");
>
> $get_image = "SELECT ImgType, ImgData FROM ImageTable WHERE
PKey=$PKey";
>
> $get_image_result = mysql_query($get_image)
> or die ("Unable to get image.");
>
> $binary_junk = mysql_result($get_image_result,0,ImgData);
> $file_type = mysql_result($get_image_result,0,ImgType);
>
> header("Content-Type: $file_type");
> header("Content-Length: " . strlen($binary_junk));
> echo "$binary_junk";
>
> ?>
>
>
>
--
################################
Michael Hall
[EMAIL PROTECTED]
[EMAIL PROTECTED]
http://openlearningcommunity.org
--
PHP General 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]
--
PHP General 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]