473,503 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get an image from a database ?

hi

i'm using a liitle script to insert images in a mssql database. yes i
know i'm not supposed to store images in a database, but after my
images are only 3kb in size, i've decided to do it anyway.

question: how would it be possible to get one of this images back on
my disc? i've been looking through many posting in different forums.
but all of them are hard to understand if you don't have any
experiences using php. the code below is as far as i could get by now.
but the downloaded file is only 318 bytes in size and can not be
displayed. so obviously, my code is crep! but what am i doing wrong?
2. question: can a file be downloaded without prompting the user in
advance? the whole application i'writing is for inhouse use only and
therefor, the user should trust these files...

any help would greatly appreciated!!

best regards


$db = mssql_connect("xxxx","xxxx","xxxx") or die("Can't connect to
mssql server.");
mssql_select_db("xxxx", $db) or die("Can't select database.");

$get_image = "SELECT IMAGE_BIN,IMAGE_NAME FROM dbo.IMAGE WHERE ID_GCP
=51 And ID_LEVEL_IMG=2";
$get_image_result = mssql_query($get_image) or die("Couldn't get
image.");

$binary = @mssql_result($get_image_result,0,"IMAGE_BIN");
$name = @mssql_result($get_image_result,0,"IMAGE_NAME");

header("Content-Disposition: attachment; filename=$name");
header("content-Type: attachment; image/jpeg");
Jul 17 '05 #1
2 2464

"Georg Andersson" <ge*************@swisstopo.ch>
news:83**************************@posting.google.c om...
hi

i'm using a liitle script to insert images in a mssql database. yes i
know i'm not supposed to store images in a database, but after my
images are only 3kb in size, i've decided to do it anyway.

question: how would it be possible to get one of this images back on
my disc? i've been looking through many posting in different forums.
but all of them are hard to understand if you don't have any
experiences using php. the code below is as far as i could get by now.
but the downloaded file is only 318 bytes in size and can not be
displayed. so obviously, my code is crep! but what am i doing wrong?
2. question: can a file be downloaded without prompting the user in
advance? the whole application i'writing is for inhouse use only and
therefor, the user should trust these files...

any help would greatly appreciated!!

best regards


$db = mssql_connect("xxxx","xxxx","xxxx") or die("Can't connect to
mssql server.");
mssql_select_db("xxxx", $db) or die("Can't select database.");

$get_image = "SELECT IMAGE_BIN,IMAGE_NAME FROM dbo.IMAGE WHERE ID_GCP
=51 And ID_LEVEL_IMG=2";
$get_image_result = mssql_query($get_image) or die("Couldn't get
image.");

$binary = @mssql_result($get_image_result,0,"IMAGE_BIN");
$name = @mssql_result($get_image_result,0,"IMAGE_NAME");

header("Content-Disposition: attachment; filename=$name");
header("content-Type: attachment; image/jpeg");

Try this:

$res=mssql_query("SELECT <field> FROM <table> WHERE <condition>")
or die("SQL ERROR in line ".__LINE__.", function mysql_query");
$image=mssql_result($res, < tablename.fieldname >);
header("Content-type: image/gif");
echo $image; // image is output to browser
if (!$handle = fopen($filename, 'w')) {
print "Cannot open file ($filename)";
exit;
}
fwrite($handle, $image);
fclose($handle); // image is output to disc
Jul 17 '05 #2
hi dennis

tx a lot! the code works fine!

best regards
Jul 17 '05 #3

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

Similar topics

2
2693
by: Ester | last post by:
Instead of drag and drop image button from Toolbox and name the image button id on the properties box, I would like to load image button ID from database. I created a database table that stores...
1
4342
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
6
3038
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
6
1895
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
13
2333
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
35
2632
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
7
11600
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
3
5224
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...
7
5386
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
10
7397
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6988
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
5578
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,...
1
5011
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...
0
4672
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...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.