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

PHP
PHP Tokenizer 学习笔记
三步搞定phpwind的静态化部署
DEDE5.3把tag标签逗号改成空格的方法分享
实例解析:从IIS的ASP迁移到APACHE的PHP
PHP读取Excel 之 Spreadsheet_Excel_Reader
PHP导出Excel 之 Spreadsheet_Excel_Writer
PDO不推广,PHP得不到发展
勇于创新,激情开拓新的未来
PHPCMS开发文档里看到PHP编码规范
一个模版引擎的诞生 开发者的思考
关于PHP开发框架
开发框架的选择和设计经验谈
框架带给我们什么(浅谈PHP框架对PHP发展的影响)
通过PHP实现DataGrid功能
php curl函数应用方法之模拟浏览器
单汉字转UNICODE
php在线打包/解包
listdir($dir) 目录读取函数
使用Apache的rewrite技术
php正则

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


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