其中db_mysql.inc.php,config.php,function.php不是真正使用到的,关键是$filename 文件名,我是通过读取数据库中的图片名称
1
2include_once ('inc/db_mysql.inc.php');
3include_once ('inc/config.php');
4include_once ('class/function.php');
5
6global $picPath;
7
8if (strstr($_SERVER[HTTP_USER_AGENT],"MSIE")) {
9$attachment = '';
10} else {
11$attachment = ' atachment;';
12}
13
14$image = getInfo('newssp_gallery','id',$_GET['id']);
15
16$filename = $picPath.$image['filename'];
17
18if (!file_exists($filename)) {
19$filename = $picPath."notexist.gif";
20}
21
22header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
23header("Cache-Control: post-check=0, pre-check=0", false);
24header("Pragma: no-cache"); // HTTP/1.0
25
26header("Content-disposition:".$attachment." filename=".$image['original']);
27
28$size = @filesize($filename);
29
30header("Content-Length: $size");
31
32$fd = @fopen($filename,rb);
33$contents = @fread($fd,$size);
34@fclose ($fd);
35
36echo $contents;
使用的时候可以把在html文件里加上
1<img height="50" src="showpic.php?id=xxx" width="50"/>
showpic.php及上面的那个php文件,id=xxx是数据库里的记录ID,width是缩略图的宽,height是缩略图的高,请不要同时宽高都上,例如,你要实现宽为50的缩略图,只要
1<img src="showpic.php?id=xxx" width="50"/>
这样就可以了