时间:2021-07-01 10:21:17 帮助过:22人阅读
public function GoodsUploadify() {
if (! empty ( $_FILES )) {
if (isset ( $_POST ['sessionid'] )) {
session_id ( $_POST ['sessionid'] );
session_start (); // 注意此函数要在session_id之后
}
import ( 'Org.Net.UploadFile' );
$upload = new \UploadFile ();
$upload->maxSize = 3292200;
$upload->allowExts = explode ( ',', 'jpg,gif,png,jpeg' );
$upload->savePath = "./public/GoodsImages/";
// 设置需要生成缩略图,仅对图像文件有效
$upload->thumb = true;
// 设置需要生成缩略图的文件后缀
$upload->thumbPrefix = 'z_,s_'; // 生产2张缩略图
// 设置引用图片类库包路径
$upload->thumbMaxWidth = '520,225';
// 设置缩略图最大高度
$upload->thumbMaxHeight = '520,225';
// 设置上传文件规则
$upload->saveRule = 'uniqid';
// 删除原图
// $upload->thumbRemoveOrigin = true;
$this->ajaxReturn ( 1, 'json' );
if (! $upload->upload ()) { // 上传错误提示错误信息
$this->ajaxReturn ( 2, 'json' );
$this->ajaxReturn ($upload->getErrorMsg (), 0, 'json' );
} else { // 上传成功 获取上传文件信息
$this->ajaxReturn ( 3, 'json' );
$info = $upload->getUploadFileInfo ();
$temp_size = getimagesize ( "./public/GoodsImages/" . $info ['0'] ['savename'] );
if ($temp_size [0] < 100 || $temp_size [1] < 100) { // 判断宽和高是否符合要求
$this->ajaxReturn ( 0, '图片宽或高不得小于100px!', 0, 'json' );
}
$data ['picName'] = $info ['0'] ['savename'];
$data ['status'] = 1;
$data ['url'] = $data ['picName'];
$data ['info'] = $info;
$this->ajaxReturn ( $data, 'json' );
}
}
}