HI all,
I am able to upload the image as blob to mysql. but while displaying the image i cant display it properly .
The code used for uploading image to mysql inserts data into mysql table.The uploading code is: -
MYSQL_CONNECT("localhost","root","");
-
mysql_select_db("sample");
-
-
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
-
-
$result=MYSQL_QUERY("INSERT INTO PHOTO(description,bin_data,filename,filesize,filetype) ".
-
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
-
The code used for displaying the image is as follows -
<?php
-
MYSQL_CONNECT("localhost","root","");
-
mysql_select_db("sample");
-
-
$id=2;
-
-
$query = "select filename,filetype,filesize,bin_data from PHOTO where id=$id";
-
-
$result = mysql_query($query) or die('Error, query failed');
-
//$ROW = mysql_fetch_assocc($result);
-
list($name, $type, $size, $content) = mysql_fetch_array($result);
-
-
echo '<meta http-equiv="Content-Type" content="img/jpg" />';
-
echo $content;
-
exit;
-
-
?>
-
This code displays some random characters all over the browser but not the image. I think i have been missing some statements .
Thank you
4 8124
You have to set the headers properly.
Read this tutorial. (scroll down to the part about downloading.)
this might help u
[PHP]$query = "SELECT Doc,Doc1,Doc2,Name,Name1,Name2 FROM xyz WHERE id = '".$id."'";
$result = mysql_query($query) or die('Error, query failed');
list($Doc,$Doc1,$Doc2,$Name,$Name1,$Name2) = mysql_fetch_array($result);
//header("Content-length: $size");
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
//header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1 changed on 27th july commented this and next line and addedprevious 3 lines for IE caching prob
//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=$Name");
echo $Name;
echo $Doc;
[/PHP]
this might help u
[PHP]$query = "SELECT Doc,Doc1,Doc2,Name,Name1,Name2 FROM xyz WHERE id = '".$id."'";
$result = mysql_query($query) or die('Error, query failed');
list($Doc,$Doc1,$Doc2,$Name,$Name1,$Name2) = mysql_fetch_array($result);
//header("Content-length: $size");
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
//header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1 changed on 27th july commented this and next line and addedprevious 3 lines for IE caching prob
//header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=$Name");
echo $Name;
echo $Doc;
[/PHP]
He's not trying to download a pdf.
Hey really srry ...i did not notice tht,,this is wht wll work for him
[PHP]
error_reporting(E_ALL);
$link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("xyz") or die(mysql_error());
$sql = "SELECT Pic FROM abc WHERE ID='".$_GET['Id']."'";
//'".$_GET['Id']."'";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
header("Content-type: image/jpeg");
$test=mysql_result($result,0);
$desired_width = 85;
$desired_height = 110;
$im = imagecreatefromstring($test);
$new = imagecreatetruecolor($desired_width, $desired_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);
imagedestroy($im);
header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-type: image/jpeg');
imagejpeg($new, NULL, 85);
imagedestroy($new);
// echo $test;
mysql_close($link);
[/PHP]
Sign in to post your reply or Sign up for a free account.
Similar topics
by: owardman |
last post by:
Dear All.
Informix 9.3 Solaris 9
MySQL 4.1.10 Linux
I am trying to migrate blob data from Informix to MySQL. Has anybody
managed this successfully and if so how?
Thanks in advance
|
by: RedSouljaz |
last post by:
Hi,
How to display image that was saved in database ms sql
server 2000 into picture box. The field type that I use
in database is Images
I can save to database but cannot show from database.
...
|
by: den 2005 |
last post by:
Hi everyone,
Here is code working on..Trying to insert record with a column with Image
or VarBinary datatype in sql database from a existing jpeg image file, then
retrieve this image from...
|
by: sang |
last post by:
Hi
i am doing my project in Mysql and PHP. My problem is i want to send a Blob field to my email using the Php. That is i am storing Candidates Resume in Blob field(Document format). I want to...
|
by: jamal8t2 |
last post by:
i have inserted blob data in database , but i am not able to access back that data to the browser. i have php script but it does not work proprly.
our script is below
if ($_REQUEST == 1) {
...
|
by: faizalahmd |
last post by:
How to display image in image control , which is retrieved from the data base . using c# in asp.net
regards,
FAIZAL AHMED.H
|
by: waleedmazhar |
last post by:
Hello Everybody
Can anybody tell me when to save images in mysql blob and when save image folder and save the image name in database.
which is more better saving image into database or save it...
|
by: phpmagesh |
last post by:
Hi
I have tried this sample code in my database for file update, but some error occurred.
everything is going fine. uploaded the file successfully but, when i download the file which i...
|
by: Abhilash Etikala |
last post by:
I am having a problem in displaying the image. Image is stored perfectly but not able to retrieve and display...i tried to knowledge but still not able to get it..
my code is:
display.php
...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |