想當初做網站處理圖片的部分
我都是包Upload這個class來做圖片的處理
http://www.verot.net/php_class_upload_docs.htm
現在用yii的framework
想不到也可以用
這邊下載
http://www.yiiframework.com/extension/upload/
安裝方法就是整包丟進extension
然後這邊是我的sample code
Yii::import('application.extensions.upload.Upload');
// receive file from post
if (isset($_FILES['pic'])) {
$Upload = new Upload($_FILES['pic']);
$Upload -> jpeg_quality = 100;
$Upload -> no_script = false;
$Upload -> image_resize = true;
$Upload -> image_x = 700;
$Upload -> image_y = 500;
$Upload -> image_ratio = true;
// some vars
$destPath = Yii::app() -> getBasePath() . '/../img/origin/' . $this -> id . '/';
$destName = $item -> id;
// verify if was uploaded
//origin img
if ($Upload -> uploaded) {
$Upload -> file_new_name_body = $item -> id;
$Upload -> file_new_name_ext = 'png';
$Upload -> file_auto_rename = false;
$Upload -> file_overwrite = true;
$Upload -> process($destPath);
}
//thumb
$destPath = Yii::app() -> getBasePath() . '/../img/thumb/' . $this -> id . '/';
if ($Upload -> uploaded) {
$Upload -> file_new_name_body = $item -> id;
$Upload -> file_new_name_ext = 'png';
$Upload -> file_auto_rename = false;
$Upload -> file_overwrite = true;
$Upload -> image_resize = true;
$Upload -> image_x = 120;
$Upload -> image_y = 180;
$Upload -> image_ratio = true;
$Upload -> process($destPath);
}
}
沒有留言:
發佈留言