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

PHP
PHP 5.0对象模型深度探索之访问方式
解决phpMyAdmin2.6以上版本数据乱码问题
PHP开发中session应用详解
Lore Article.PHP SQL注入漏洞
Mysql存取session实例
php调用mysql存储过程和函数的方法
用PHP5进行三层开发
在PHP中进行GB2312与UTF-8的互换
php与XML、XSLT、Mysql的结合运用,代码篇
php与XML、XSLT、Mysql的结合运用,安装篇
用GD图库生成横竖柱状图折线图的类
一个全面获取图象信息的函数getImageInfo()
用PHP与XML联手进行网站编程
PHPMailer:Featured email transfer class for PHP
php用流方式制作缩略图
php+odbc+access数据库操作函数,在windows下测试通过
PHP IPwhois类
用PHP读写NTFS文件系统下的文件摘要信息
一个简单上传文件出错的解决
PHP实现自动刷数和“灌水”机

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


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