我正在使用Uploadify
和class.upload.php
上传和操作图像。 这里是我的代码。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框架。
使用class.upload.php完成,但只能在上传之后完成。 – Red