473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

retrieve image from MySQL with php error

the script that show image is :

<?php
include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: '.$filetype);
header("Content-Disposition: attachement\n");
print $file;
?>

it's work fine execpt it show the image as a attachement
(Save as... window), so Apache, mysql, php seem to work fine.
the problem is only on http header of image i think.
i want the image directly so, i use this :

<?php
include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: '.$filetype);
print $file;
?>

it's don't work, firefox gave me "The image
http://ip:8080/viewimage.php
cannot be displayed, because it contains error."
IE show me nothing at all.

any one have a idea ?

----------------------------------------------------
Windows NT 5.1 build 2600 (XP Professional English)
Apache 2.0.54, running as a server
PHP Version 5.0.4 running as module
MySQL 4.1.7 (a dll from php)
Firefox english 1.0.4
Internet Explorer 6

th**********@gmail.com

Jul 17 '05 #1
7 3568


th**********@gmail.com wrote:
the script that show image is :

<?php
include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: '.$filetype);
header("Content-Disposition: attachement\n");
print $file;
?>

it's work fine execpt it show the image as a attachement
(Save as... window), so Apache, mysql, php seem to work fine.
the problem is only on http header of image i think.
i want the image directly so, i use this :

<?php
include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: '.$filetype);
print $file;
?>

it's don't work, firefox gave me "The image
http://ip:8080/viewimage.php
cannot be displayed, because it contains error."
IE show me nothing at all.

any one have a idea ?

----------------------------------------------------
Windows NT 5.1 build 2600 (XP Professional English)
Apache 2.0.54, running as a server
PHP Version 5.0.4 running as module
MySQL 4.1.7 (a dll from php)
Firefox english 1.0.4
Internet Explorer 6

th**********@gmail.com


The content-type is more than just the file extension. Here are some
common ones for images:

image/gif
image/jpeg
image/bmp
image/png

Here's a decent list to check out:

http://www.utoronto.ca/webdocs/HTMLd...type.html#imag

Jul 17 '05 #2
yeah i know, the file type is ok, since it work as attachement

Jul 17 '05 #3
On 6 Jun 2005 14:38:43 -0700, "ZeldorBlat" <ze********@gmail.com> wrote:
The content-type is more than just the file extension. Here are some
common ones for images:

image/gif
image/jpeg
image/bmp
image/png

Here's a decent list to check out:

http://www.utoronto.ca/webdocs/HTMLd...type.html#imag


And for comparison here's the Official list - which (by definition) doesn't
cover the "type/x-something" values

http://www.iana.org/assignments/media-types/

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4
On 6 Jun 2005 13:18:19 -0700, "th**********@gmail.com" <th**********@gmail.com>
wrote:
<?php
include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: '.$filetype);
print $file;
?>

it's don't work, firefox gave me "The image
http://ip:8080/viewimage.php
cannot be displayed, because it contains error."
IE show me nothing at all.

any one have a idea ?


One trick to debugging dynamic generation of images is to add in a
header("Content-type: text/plain"), so you can see the output.

A common error is that there is blank space, or even an error or warning
message produced, which the browser then tries (and fails) to interpret as
image data. When displayed as text you can see this.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
with :
<?php

include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: text/plain');
print $file;
?>
it's open a window save as...viewimage.php
i rename the file to viewimage.jpg it's the image i want to show
try it maybe it will help
http://24.203.86.30:8080/viewimage.php

Jul 17 '05 #6
On 6 Jun 2005 15:15:41 -0700, "th**********@gmail.com" <th**********@gmail.com>
wrote:
with :
<?php

include('dbinfo.inc.php');

mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT file,filesize,filetype FROM user WHERE id=1;";
$result=mysql_query($query);
mysql_close();

$file=mysql_result($result,0,"file");
$filesize=mysql_result($result,0,"filesize");
$filetype=mysql_result($result,0,"filetype");

header('Content-Type: text/plain');
print $file;
?>
it's open a window save as...viewimage.php
i rename the file to viewimage.jpg it's the image i want to show
try it maybe it will help
http://24.203.86.30:8080/viewimage.php


andyh@server:~/tmp$ GET http://24.203.86.30:8080/viewimage.php | hexdump -C -n
128
00000000 20 ff d8 ff e0 00 10 4a 46 49 46 00 01 02 00 00 | ÿØÿà..JFIF.....|
00000010 64 00 64 00 00 ff ec 00 11 44 75 63 6b 79 00 01 |d.d..ÿì..Ducky..|
00000020 00 04 00 00 00 50 00 00 ff ee 00 26 41 64 6f 62 |.....P..ÿî.&Adob|
00000030 65 00 64 c0 00 00 00 01 03 00 15 04 03 06 0a 0d |e.dÀ............|
00000040 00 01 6a a1 00 02 35 06 00 03 ea af 00 07 01 da |..j¡..5...ê¯...Ú|
00000050 ff db 00 84 00 02 02 02 02 02 02 02 02 02 02 03 |ÿÛ..............|
00000060 02 02 02 03 04 03 02 02 03 04 05 04 04 04 04 04 |................|
00000070 05 06 05 05 05 05 05 05 06 06 07 07 08 07 07 06 |................|
00000080

JFIF is supposed to start with the SOI marker "ff d8" - you've got a leading
20 - which is a space character.

Check your source code for a space - I would particularly check dbinfo.inc.php
as there doesn't appear to be a space in the code you posted.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #7
ok thanks a lot
i was a tralling space after the <?php ?> in dbinfo.inc.php

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
3
by: | last post by:
Hi, I have a SQL Server database table where one of the columns is of type Image. The problem occurs when I try to retrieve images from the table. I'm using the following C# code: ...
2
by: webmechanic | last post by:
I was able to insert images into mysql stored as binary data. How do I retrieve it. Please provide thorough explanation. Thanks.
2
by: Noctiluca | last post by:
Hi folks, Very much a learner when it comes to programming so excuse me if this is a silly question... I'm trying to generate a map of the positions of moth records in a mysql database using PHP...
3
by: gsoguerrilla | last post by:
Hi, I have limited knowledge in php and I am having trouble with uploading an image to a remote directory and resizing it if it's larger and renaming it to a unique id, while at the same time I...
2
by: Adam Teale | last post by:
hey guys Is there a builtin/standard install method in python for retrieving or finding out an image's dimensions? A quick google found me this:...
3
by: alexseow | last post by:
<img src="image.asp?id=1"> --------------------------------------------------------------- <%Option Explicit%> <!-- #include file="IMS/includes/dbconn.asp"--> <% dim MyConn,SQL Set MyConn...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.