程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP用流方式制作縮略圖

PHP用流方式制作縮略圖

編輯:關於PHP編程

其中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的縮略圖,只要這樣就可以了。

(責任編輯:

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved