天天看点

Discuz!图片附件获取缩略图路径makethumbpath以及生成缩略图方法

定义文件:

\source\class\helper\helper_attach.php
           

方法定义:

public static function makethumbpath($id, $w, $h){
		$dw = intval($w);
		$dh = intval($h);
		$_daid = sprintf("%09d", $id);
		$dir1 = substr($_daid, 0, 3);
		$dir2 = substr($_daid, 3, 2);
		$dir3 = substr($_daid, 5, 2);
		return $dir1.'/'.$dir2.'/'.$dir3.'/'.substr($_daid, -2).'_'.$dw.'_'.$dh.'.jpg';
	}
           

参数说明:

$id:附件aid

$w:缩略图宽度

$h:缩略图高度

使用方法:

$path=helper_attach::makethumbpath($aid, $width,$height);
           

完整路径:

'\data\attachment\image\'.$path;
           

缩略图生成方法:

require_once libfile('class/image');
$img = new image;
$img->Thumb($filename, $path, $w, $h, $type);
           

其中$filename为改附件图片的原始路径

$filename = $_G['setting']['attachdir'].'forum/'.$attach['attachment'];