•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,475 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,259 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3247 | Replies: 6
![]() |
•
•
Join Date: May 2007
Posts: 60
Reputation:
Rep Power: 2
Solved Threads: 0
Hello guys! Greetings to everyone!
I have tried the following code but it doesn't display images, it only stores data.
Here's the code in displaying images:
<?php
if ($submit) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$data = addslashes(fread(fopen($form_data, "rb"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
print "<img src=getdata.php?id=".$id ."/>";
MYSQL_CLOSE();
} else {
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" 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" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
It stores data in my database(means working, please check if there is conflict. i hope i dont bother any of you) thanks..
Here's code in storing images:
<?php
if($id) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$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;
}
?>
No errors but none of the images stored in the database display. please help me troubleshooting this. thanks a lot.
Below is the list of fields i have created.
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
)
I have tried the following code but it doesn't display images, it only stores data.
Here's the code in displaying images:
<?php
if ($submit) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$data = addslashes(fread(fopen($form_data, "rb"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
print "<img src=getdata.php?id=".$id ."/>";
MYSQL_CLOSE();
} else {
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" 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" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
It stores data in my database(means working, please check if there is conflict. i hope i dont bother any of you) thanks..

Here's code in storing images:
<?php
if($id) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$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;
}
?>
No errors but none of the images stored in the database display. please help me troubleshooting this. thanks a lot.

Below is the list of fields i have created.
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
)
Last edited by dudegio : Sep 7th, 2007 at 1:29 am.
•
•
Join Date: May 2007
Posts: 60
Reputation:
Rep Power: 2
Solved Threads: 0
Hello guys! I got the idea of displaying the image from the database. I have created a different database and i place this code:
<?php
dbconnect();
$queryresult= mysql_query("SELECT * FROM tbl_gallery limit 0,9") or die("SELECT Error: ".mysql_error());
while ($rec=mysql_fetch_array($queryresult, MYSQL_ASSOC)){
print '<div id="gallery-category"><img src="getdata.php?id='.$rec["event_id"].'"/><div id="gallery-category-title"><img src="images/gallery/folder.gif" />';
print $rec["event_title"].'<br/><div id="gallery-category-date">'.$rec["event_date"].'</div></div></div>';
}
print '<div id="gallery-spacer1"> </div>';
}
?>
Filename is viewimage.php.
This works in my localhost. Im using PHP 4.1 version in my localhost.
But when i uploaded this to my domain, the image doesn't display and can only store images. The PHP version i have used is 5.0 in my domain. Is there a conflict on the version or can you figure out the error? It doesnt display images to my domain but in my localhost its working. pls help me on how to troubleshoot this. thanks a lot.
Another thing is, you will see at the status bar that prompt messages dowloading images but there were no images display. please please help.
<?php
dbconnect();
$queryresult= mysql_query("SELECT * FROM tbl_gallery limit 0,9") or die("SELECT Error: ".mysql_error());
while ($rec=mysql_fetch_array($queryresult, MYSQL_ASSOC)){
print '<div id="gallery-category"><img src="getdata.php?id='.$rec["event_id"].'"/><div id="gallery-category-title"><img src="images/gallery/folder.gif" />';
print $rec["event_title"].'<br/><div id="gallery-category-date">'.$rec["event_date"].'</div></div></div>';
}
print '<div id="gallery-spacer1"> </div>';
}
?>
Filename is viewimage.php.
This works in my localhost. Im using PHP 4.1 version in my localhost.
But when i uploaded this to my domain, the image doesn't display and can only store images. The PHP version i have used is 5.0 in my domain. Is there a conflict on the version or can you figure out the error? It doesnt display images to my domain but in my localhost its working. pls help me on how to troubleshoot this. thanks a lot.

Another thing is, you will see at the status bar that prompt messages dowloading images but there were no images display. please please help.
Last edited by dudegio : Sep 9th, 2007 at 11:49 pm.
•
•
Join Date: May 2007
Posts: 60
Reputation:
Rep Power: 2
Solved Threads: 0
I have created a directory. There is no path specified since i have used the data type blobs to the image_data whom i store the images. Is there something wrong or something is restricting on the domain to display images that stored in the database? I placed all three pages in one directory like what i did in my localhost. please help.
Last edited by dudegio : Sep 10th, 2007 at 9:43 pm.
•
•
Join Date: May 2007
Posts: 60
Reputation:
Rep Power: 2
Solved Threads: 0
I already found out the error why it doesn't display the image. It is in the version of the PHP. Anyone knows how to change this code to PHP version 5. please please help guys.. Thanks a lot.
<?php
if($id) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$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
if($id) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$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;
}
?>
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I was having issues displaying the image in a browser. After a lot of troubleshooting, I realized the php.ini file had set_magic_quotes_runtime = On. This was causing my problem. I can leave the php.ini alone and change it inline.
Depending on what you are doing, you may need to turn it off when reading the data into the database, and also when returning the data to the browser.
Hope this saves someone else some frustration.
<? set_magic_quotes_runtime(0); // turn off ?> scripts here <? set_magic_quotes_runtime(1); // turn back on ?>
Depending on what you are doing, you may need to turn it off when reading the data into the database, and also when returning the data to the browser.
Hope this saves someone else some frustration.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- How insert image into mysql database and retrieve (PHP)
- how to save image into database (VB.NET)
- Two monitors displaying identical image? (Monitors, Displays and Video Cards)
- Displaying Images( buffered data ) from the Database using Java (Java)
- retieve image from database (ASP.NET)
- uploading image in database (PHP)
Other Threads in the PHP Forum
- Previous Thread: PHP auto-save code
- Next Thread: Displaying Random Result from Mysql



Linear Mode