其中db_MySQL.inc.php,config.php,function.php不是真正使用到的,關鍵是$filename 檔案名稱,我是通過讀取資料庫中的圖片名稱
include_once ('inc/db_mysql.inc.php');
include_once ('inc/config.php');
include_once ('class/function.php');
global $picPath;
if (strstr($_SERVER[HTTP_USER_AGENT],"MSIE")) {
$attachment = '';
} else {
$attachment = ' atachment;';
}
$image = getInfo('newssp_gallery','id',$_GET['id']);
$filename = $picPath.$image['filename'];
if (!file_exists($filename)) {
$filename = $picPath."notexist.gif";
}
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, PRe-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
header("Content-disposition:".$attachment." filename=".$image['original']);
$size = @filesize($filename);
header("Content-Length: $size");
$fd = @fopen($filename,rb);
$contents = @fread($fd,$size);
@fclose ($fd);
echo $contents;
?>
使用的時候可以把在html檔案裡加上
showpic.php及上面的那個php檔案,id=xxx是資料庫裡的記錄ID,width是縮圖的寬,height是縮圖的高,請不要同時寬高都上,例如,你要實現寬為50的縮圖,只要這樣就可以了