各種圖案窗簾、精美壁紙、壁貼
專業到府丈量、送樣估價,是您輕鬆裝潢的好選擇
殺價網解決各類白蟻困擾,專業白蟻防治工程
收費合理,免費到府勘查

首頁  •  j2h 論壇 • 程式設計討論     • 

[轉貼]simple album

房東:妹妹
發表時間:2007-12-11
[檢舉]


album = new album;
$album->setdir('./album/');
$album->savephoto( $_FILES['file']['tmp_name'] , $_FILES['file']['type'] );
引用:
class album{
#default size
var $limit = array('w'=>80,'h'=>80);
var $q=80;

function setlimit($pixelw,$pixelh){ $this->limit = array('w'=>$pixelw,'h'=>$pixelh); }
function setquality($num){ $this->q = $num;}

#圖片的目錄
function setdir($dir){
$this->al_dir = $dir;
$this->als_dir = $this->al_dir . 'thumbs/';

if( !file_exists($this->al_dir) )
mkdir($this->al_dir);
if( !file_exists($this->als_dir) )
mkdir($this->als_dir);
}


function mk_rname($file_type){
#產生檔案名稱
$name = uniqid(\"\");

switch( $file_type )
{
case 'image/pjpeg':
$name .= '.jpg';
break;

case 'image/gif':
$name .= '.gif';
break;

case 'image/png':
$name .= '.png';
break;

default:
echo '不正確的檔案格式:'.$file_type;
echo '
允許\的檔案格式: jpeg , gif ,png';
exit();
return 0;
break;
}
return $name;

}

function savephoto( $file_tmpname, $file_type ){
#確認檔案上傳
if( !is_uploaded_file( $file_tmpname ) )
return false;

###建立檔案
###############################
#設定檔名
$new_name = $this->mk_rname( $file_type );
#重抓檔名
while( file_exists($this->al_dir.$new_name) ){ $new_name=$this->mk_rname( $file_type ); }
echo '新檔名:'.$new_name.'
';

if( !copy( $file_tmpname , $this->al_dir.$new_name) )
return false;

###建立縮圖
###############################
#從檔案建立畫布
switch( $file_type ){
case 'image/pjpeg':
$im = ImageCreateFromJPEG ( $file_tmpname ) or Die(\"不是正確的JPG檔\");
break;

case 'image/gif':
$im = ImageCreateFromGif ( $file_tmpname ) or Die(\"不是正確的gif檔\");
break;

case 'image/png':
$im = ImageCreateFromPng ( $file_tmpname ) or Die(\"不是正確的png檔\");
break;

default:
return 0;
break;
}
$src_h = ImageSY($im );
$src_w = ImageSX($im );
$dst_h = $src_h;
$dst_w = $src_w;

#定義縮小值
if($src_h>$this->limit['h'] OR $src_w>$this->limit['w']){
if($src_h > $src_w)
$rate = $src_h / $this->limit['h'];
else
$rate = $src_w / $this->limit['w'];

$dst_h = $src_h / $rate;
$dst_w = $src_w / $rate;
}
#建立新畫布
$im2= ImageCreateTrueColor( $dst_w, $dst_h);
imagecopyresized ($im2, $im, 0,0, 0,0, $dst_w, $dst_h , $src_w, $src_h);
switch( $file_type ){
case 'image/pjpeg':
ImageJPEG($im2,$this->als_dir.$new_name, $this->q );
break;
case 'image/gif':
ImageGIF($im2,$this->als_dir.$new_name);
break;
case 'image/png':
ImagePNG($im2,$this->als_dir.$new_name);
break;
default:
return false;
break;

}

#刪除暫存檔
unlink( $file_tmpname );
#傳回檔案名稱
return $new_name;

}

function delphoto($filename){
if(unlink( $this->al_dir.$filename) AND unlink($this->als_dir.$filename))
return true;
else
return false;
}

#Class End
}



  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務



  •  共 0 人回應

    姓名:
    佈告內容: