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

PHP
PHP脚本中include文件出错解决方法
织梦cms的php采集类
php大文件上传经典源码
(PHP技巧)setcookie语句的问题
PHP安装全攻略:APACHE
PHP和JS实现普通HTTP上安全地传输密码
一个数据库备份类
PHP生成中文拼音
轻松实现php代码防注入,保护代码安全
PHP在网站开发中的一些优势
php自动更新新闻diy _php实例
php实现文件安全下载
php操作access数据库类代码
自定义PHP分页函数
一个简单实用的php加图片水印函数
PHP在Web开发领域的优势
学习php中10个基础知识总结
IIS6.0平台下PHP最佳配置方法
PHP 5.2.8 紧急发布 修复5.2.7严重漏洞
升级PHP5的理由:PHP4和PHP5性能大对比

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


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