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

PHP
PHP实现网页自动更新块
PHP 5.0 中的对象重载技术研究
轻型数据库SQLite结合PHP的开发
PHP中模板分页的处理
在debian下为PHP5.0.3安装pdo模块
PHP下实现端口复用/劫持
PHP链接ACCESS数据库最简单的方法
IIS 不用 rewrite 实现页面静态化的方法
PHP发现安全漏洞
Windows下PHP4.0与Oracle 8的连接设置
使用OOP技术来优化PHP应用程序
用MySQL和PHP创建XML
正则表达式中的特殊字符一览
截获网站
在UNIX平台上的Netscape Enterprise Server 3.x下配置PHP
Windows 98下安装Apache(PWS) PHP4MySQLphpMyAdmin的方法
对《Windows 9x/NT下以Apache的模块方式安装PHP4》的补充
Windows2000下安装Apache PHP4 MySQL
在WIN98下安装PHP4+ PERSONAL ORACLE8I
在 PHP 中用描点法“绘制”中文

PHP技术进阶:php用流方式制作缩略图


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 114 ::
收藏到网摘: 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'>这样就可以了