当前位置: 首页 > 图文教程 > 网络编程 > PHP > php用流方式制作缩略图

PHP
我的论坛源代码(三)
我的论坛源代码(二)
杏林同学录(七)
杏林同学录(八)
我的论坛源代码(十)
我的论坛源代码(九)
杏林同学录(九)
支持oicq头像的留言簿(二)
支持oicq头像的留言簿(一)
一个简单实现多条件查询的例子
不用数据库的多用户文件自由上传投票系统(1)
模仿OSO的论坛(二)
簡繁体转换的class
从C/C++迁移到PHP:判断字符类型的函数
PHP编程之高级技巧:利用Mysql函数
让你同时上传 1000 个文件 (二)
一个好用的分页函数
php环境配置 php5 mysql5 apache2 phpmyadmin安装与配置
PHP编程中八种常见的文件操作方式
给初学PHP的5个入手程序

PHP 中的 php用流方式制作缩略图


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 67 ::
收藏到网摘: n/a

 

其中db_mysql.inc.php,config.php,function.php不是真正使用到的,关键是$filename 文件名,我是通过读取数据库中的图片名称

<?php
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文件里加上

<img src='showpic.php?id=xxx' width='50' height='50'>

showpic.php及上面的那个php文件,id=xxx是数据库里的记录ID,width是缩略图的宽,height是缩略图的高,请不要同时宽高都上,例如,你要实现宽为50的缩略图,只要<img src='showpic.php?id=xxx' width='50'>这样就可以了