您的位置:首頁技術文章
文章詳情頁

php用流方式制作縮略圖

瀏覽:81日期:2024-02-01 13:08:09

其中db_mysql.inc.php,config.php,function.php不是真正使用到的,關鍵是$filename 文件名,我是通過讀取數據庫中的圖片名稱

<?phpinclude_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.1header('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文件里加上

<img src='http://www.wxshucaidpc.com/bcjs/showpic.php?id=xxx' height='50'>

showpic.php及上面的那個php文件,id=xxx是數據庫里的記錄ID,width是縮略圖的寬,height是縮略圖的高,請不要同時寬高都上,例如,你要實現寬為50的縮略圖,只要<img src='http://www.wxshucaidpc.com/bcjs/showpic.php?id=xxx' width='50'>這樣就可以了

標簽: PHP
国产综合久久一区二区三区