【发布时间】:2012-01-09 13:16:53
【问题描述】:
我正在使用Uploadify 和class.upload.php 上传和处理图像。
这是我的代码。
require_once('/style/scripts/crop/class.upload.php');
if (!empty($_FILES)) {
$uc = $this->input->post('username');
$_REQUEST['folder'] = "/project/user/".$uc."/pages".$_REQUEST['folder']."/images/gallery";
$targetPath = $_SERVER['DOCUMENT_ROOT'] .$_REQUEST['folder']. '/';
$pic_temp = random_string('alnum',10);
$handle = new Upload($_FILES['Filedata']);
if ($handle->uploaded) {
$handle->file_src_name_body = $pic_temp; // hard name
$handle->file_overwrite = true;
$handle->file_auto_rename = false;
$handle->image_resize = false;
$handle->image_ratio_y = false;
$handle->image_x = ($handle->image_src_x < 400)?$handle->image_src_x:400;
$handle->file_max_size = '999999'; // max size
$handle->Process($targetPath);
$handle->clean();
if ($handle->processed)
$json = array("result" => 1,
"file" => $_REQUEST['folder'].'/'.$handle->file_dst_name.'?'.time(),
"imagewidth" => $handle->image_dst_x,
"imageheight" => $handle->image_dst_y
);
else
$json = array("result" => 0);
$encoded = json_encode($json);
echo $encoded;
unset($encoded);
}
else {
$json = array("result" => 0);
$encoded = json_encode($json);
echo $encoded;
unset($encoded);
}
现在我想在上传前检查文件大小, 如果图像大小超过 1MB,则应重新调整大小 [禁止裁剪或其他内容...] 以节省磁盘空间。 如果小于 1MB 则直接上传。
我怎样才能做到这一点?
该项目正在使用 Codeigniter 框架。
【问题讨论】:
标签: php codeigniter image-processing upload