找回密码
 成为会员

新浪微博登陆

只需一步, 快速开始

搜索
0赞
赞赏
手机版
扫码打开手机版
把文字装进口袋

php用流方式制作缩略图

冰客 2008-11-7 14:52:41
其中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'>这样就可以了
您需要登录后才可以回帖 立即登录 新浪微博登陆
小帖士
如果你不是特别对他的每一句话感兴趣,不要随意用"关注"人的功能,因为关注以后,他的所有发帖回帖都会以通知的方式提醒你的!
统计信息
  • 会员数: 4661 个
  • 话题数: 8709 篇
  • 巅峰数: 8 人
返回顶部