473,403 Members | 2,359 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,403 software developers and data experts.

displaying images.

i used a code from a website that allows you to display images. however everything works fine from storing the image to the database but it does not display the image.

the following code is the one i have used.

Storing the images:

[PHP]<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>

<?php

if (isset($_REQUEST['submit'])) {

mysql_connect("localhost","root","");
mysql_select_db("binary_data");

$data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), $_FILES['form_data']['size']));

$result= mysql_query("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('".$form_description."','".$data."','".$_FILES['form_data']['name']."','".$_FILES['form_data']['size']."','".$_FILES['form_data']['type']."')");

$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";

mysql_close();

} else {
?>
<form method="post" action="store.php" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data">
<p><input type="submit" name="submit" value="submit">
</form>

<?php

}

?>[/PHP]

Getting the image from database :

[PHP]<?php

if($id) {

mysql_connect("localhost","root","");

mysql_select_db("binary_data");

$query = "select bin_data,filetype from table where id='$id'";
$result = mysql_query($query);

$data = mysql_result($result,0,"bin_data");
$type = mysql_result($result,0,"filetype");

header( "Content-type: $type");
header( "Content-type: image/pjpeg");
echo $data;


};
?>[/PHP]

displaying the image:

[PHP]<html>
<head>
<title>images retrieved from database</title>
</head>

<body>

<img src="getdata.php?id=3">

</body>
</html>[/PHP]

if someone can help i would greatly appreciate it.

thanks

ashraf
Mar 21 '08 #1
14 2081
hsriat
1,654 Expert 1GB
Open getdata.php?id=3 in your browser.
See what error it gives.

It should be $_GET['id'] instead of $id
Mar 22 '08 #2
Markus
6,050 Expert 4TB
Open getdata.php?id=3 in your browser.
See what error it gives.

It should be $_GET['id'] instead of $id
More over, should be:
[php]
$id = $_GET['id']; # do some cleaning of this.
[/php]
You should, also, sanitize that input; it could be malicious.

Regards.
Mar 22 '08 #3
thanks for ur reply guys

but still no luck i'v tried both ways. i'm new to php and i have an assignment to hand in soon. anymore suggestion.

do u think storing the url to the images would be easier?

thanks in advance.

ashraf
Mar 22 '08 #4
hsriat
1,654 Expert 1GB
thanks for ur reply guys

but still no luck i'v tried both ways. i'm new to php and i have an assignment to hand in soon. anymore suggestion.

do u think storing the url to the images would be easier?

thanks in advance.

ashraf
What error do you get when you open getdata.php?id=3 in your browser?
Mar 22 '08 #5
i get no error just a blank screen
Mar 22 '08 #6
What error do you get when you open getdata.php?id=3 in your browser?
sorry i only put in getdata.php not getdata.php?id=3

this is the following erros i get on the page.


Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\getdata.php on line 13

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\getdata.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\getdata.php:13) in C:\wamp\www\getdata.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\getdata.php:13) in C:\wamp\www\getdata.php on line 17
Mar 22 '08 #7
i've sorted the problem out. i looked at the errors and figured out wat was wrong in mysql_query it said select from table instead of the actual table name.

thanks anyway i wouldn't have found that out if u didn't tell me to look at the errors on that particular script. nice one "hsriat" and "markusn00b"
Mar 22 '08 #8
Markus
6,050 Expert 4TB
Try using a while loop to assign the data:
[php]
$_res = mysql_query("SELECT .... ");
while($_rows = mysql_fetch_array($_res))
{
$_data = $_rows['bin_data'];
$_file = $_rows['filetype'];
}
[/PHP]

Regards.

EDIT: Neglect this then.

Glad you've sorted it!
Mar 22 '08 #9
ronverdonk
4,258 Expert 4TB
Do not post duplicate threads in this forum! I does not help you in any way. It just annoys people.

The duplicate thread has been removed.

moderator
Mar 22 '08 #10
i didn't duplicate the thread. next time b4 u delete a post read the code and maybe compare the two codes and check. this code was for BLOB files and the other was for linking url files.
Mar 22 '08 #11
hsriat
1,654 Expert 1GB
i didn't duplicate the thread. next time b4 u delete a post read the code and maybe compare the two codes and check. this code was for BLOB files and the other was for linking url files.
In the code you provided in the other thread (removed one), view source of your page in a browser (recommended FF), and see what is the problem with your img tag's src attribute.
Check if the referred source actually exists.
Mar 22 '08 #12
thanx "HSRIAT" but i have sorted the problem out i did wat u said and it seemed that i forgot to put a forward slash in the code thanks any way much appreciated.
Mar 22 '08 #13
Markus
6,050 Expert 4TB
i didn't duplicate the thread. next time b4 u delete a post read the code and maybe compare the two codes and check. this code was for BLOB files and the other was for linking url files.
You DID duplicate the thread.

I read the new thread, fully, and it was in no-way different from this thread.

Even it a question was partly linked to this thread, you should keep it on the same thread.

Regards,
Mar 23 '08 #14
hsriat
1,654 Expert 1GB
You DID duplicate the thread.

I read the new thread, fully, and it was in no-way different from this thread.

Even it a question was partly linked to this thread, you should keep it on the same thread.

Regards,
It was a bit different. In that one, he was saving the name of the image in the db, and in this one, image is saved in db.

Though I'm sorry for argument.

:)
Harpreet
Mar 23 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Ian Davies | last post by:
Hello Im having problems displaying my images as thumbnails in a table. My code for producing the new width and height from the original image is as follows...
2
by: Woodmon | last post by:
I'm observing issue with linked images not displaying in either Firefox 1.5b2 or IE6 when running on Win XP (they display fine in either browser on W2k). Example problem HTML is: <a...
3
by: Dalan | last post by:
At first I was not certain what could cause Access 97 from displaying most jpeg images, but not all. After further testing, it seemed that all original images of less than 275 pixels per inch or...
1
by: tshad | last post by:
Is there some reason why the Hyperlink in a DataGrid will not show an image? I have a datagrid with the following: <asp:TemplateColumn visible="false" HeaderText="Skills"> <itemtemplate>...
1
by: David Lozzi | last post by:
Hello, I'm wondering whats the best method to use for displaying several photos' thumbnails. One method I know is to dynamically resize the photo at the time the page is loaded. What does this...
10
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the...
5
by: Tom | last post by:
VS 2003/C# Have a axWebBrowser control that will not render images. Originally our app was just launching IE7 to display an HTML page. The bitmap images were not displaying - path was correct...
4
by: redpears007 | last post by:
Hi Again, Throwing this one out to you again as i am not getting anywhere and can find little to no information out there. I am currently displaying images (Jpegs) in access via the routine...
7
by: Sonasang | last post by:
Hi , I am creating a web page in ASP. I will place some images in the folder, The images placed in the folder should be disaplayed. I am having the two button in the web page if I click next...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.