This is some script found here at phpbuilder, with modifications. Some of the script is in Norwegian - Sorry about that!
<?php
/
Update 2000-07-05
It was reported today that you get an error about
an invalid mysql link id on the last mysql_close
statement.
Look for MICHALE_VINCE_FIX to see the change
Thanks to Michael Vince
/
/*
* Update 2000-02-08
* The problem of the retrieved file always being named
* fileman.php3 seems to have been fixed.
*
* Look for SANDER_BOSMAN_FIX to see the 2 additions.
*
* Thanks to Sander Bosman (gedrain@home.nl)
*/
/*
* This script is for testing of sending and receiving files
* from a mysql database using php3.
*
* This script was typed in by Mike Leidy (mike@nerdfest.org) and was
* inspired by one written by Florian Dittmer (dittmer@gmx.net).
*
* Requred Table Schema:
*
* CREATE TABLE binary_data (
* id int(6) DEFAULT '0' NOT NULL auto_increment,
* description varchar(50) DEFAULT '' NOT NULL,
* bin_data longblob NOT NULL,
* filename varchar(50) DEFAULT '' NOT NULL,
* filesize varchar(50) DEFAULT '' NOT NULL,
* filetype varchar(50) DEFAULT '' NOT NULL,
* hits varchar(50) DEFAULT '' NOT NULL,
* PRIMARY KEY (id),
* KEY description (description),
* KEY hits (hits)
* );
*
* Other Options:
* -- added -O max_allowed_packet=24M to the startup command
* -- changed in php3.ini upload_max_filesize = 10485760
*/
/*
* Changes made by Torbjørn Engedal (torbjorn@voca.no) as well
*/
include('config.php');
include('database.php');
$bredde=@$bredde; //Width
db_connect();
$tbl = "nor_sak";//Some table name
$query = "SELECT sak_bilde, sak_filetype, sak_filename, sak_bildew, sak_bildeh FROM $tbl WHERE sak_id = $sak_id";
$res_id = db_query ($query);
if (! $res_id) {
printf ("MySQL Error: (%d) %s<br><br>%s\n",
mysql_errno (),
mysql_error (),
$query);
mysql_close ($conn_id);
exit ();
}
$row = mysql_fetch_array ($res_id);
if ($row) {
$data = $row["sak_bilde"];
$type = $row["sak_filetype"];
/*
* SANDER_BOSMAN_FIX
*/
$filename = $row["sak_filename"];
/*
* SANDER_BOSMAN_FIX
*/
if($bredde && ( $type == "image/x-png" || $type == "image/png" || $type == "image/jpg" || $type == "image/jpeg" || $type == "image/pjpeg" )){//Sjekker om bildet skal "resizes" - resizer foreløpig bare for jpg-bilder.
//Henter informasjon om gammelt bilde
$bildew = $row["sak_bildew"];
$bildeh = $row["sak_bildeh"];
$forhold = $bildeh/$bildew;
#echo "Bredde: ",$bildew,"<br>Høyde: ",$bildeh,"<br>Forhold:",$forhold,"<br><br>";//debug
$new_w=$bredde;//Ny bredde - New width
$new_h = ($new_w * $forhold);
$new_h = ceil($new_h);//Ny høyde - New height
#echo "Ny bredde: ",$new_w,"<br>Ny høyde: ",$new_h,"<br><br>";//debug
$dst_img=ImageCreate($new_w,$new_h);
$src_img=imagecreatefromstring($data);
//$src_img=ImageCreateFromGif("bilde.php?sak_id=".$sak_id);
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,$bildew,$bildeh);
Header ("Content-disposition: filename=".$filename);
Header ("Content-type: $type");
if($type == "image/jpg" || $type == "image/jpeg" || $type == "image/pjpeg")
imagejpeg($dst_img);
else if($type == "image/gif")
ImageGif($dst_img);
else if($type == "image/png" || $type == "image/x-png")
imagepng($dst_img);
else if($type == "image/wbmp")
imagewbmp($dst_img);
} else {
Header ("Content-disposition: filename=".$filename);
Header ("Content-type: $type");
echo $data;
}
exit ();
}
else {
printf ("Det ble ikke funnet noen bilder for sak med sak_id= %d\n", $sak_id);
}
?>