|
我要完成的效果是这样的:form上传一张图片,先对图片进行调整,完成上传操作并对文件进行改名,最后再对改名的文件生成一张缩略图!
目前只能实行,图片的调整、上传同时改名,就是没法生成缩略图。
$goods_id = str_pad(intval($this->input->post('goods_id')), 8, '0', STR_PAD_LEFT);
$tempFile = $_FILES['Filedata']['tmp_name'];
//获取上传文件相关信息
$file_array = pathinfo($_FILES['Filedata']['name']);
$file_ext = $file_array['extension'];
$file_name = basename($_FILES['Filedata']['name'], $file_ext);
//形成上传路径与文件名
$targetPath = $_SERVER['DOCUMENT_ROOT'] . 'goods/' . $goods_id . '/';
$new_file_name = md5($file_name . date("YmdHis"));
//图片调整
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $tempFile;
$config['maintain_ratio'] = TRUE;
$config['width'] = 308;
$config['height'] = 308;
$this->image_lib->initialize($config);
$this->image_lib->resize();
unset($config);
$this->image_lib->clear();
//下面是进行上传
move_uploaded_file($tempFile, $targetPath . $new_file_name . '.jpg');
$config['image_library'] = 'gd2';
$config['source_image'] = './goods/' . $goods_id . '/' . $new_file_name . '.jpg';
$config['maintain_ratio'] = TRUE;
$config['create_thumb'] = TRUE;
$config['width'] = 36;
$config['height'] = 36;
$this->image_lib->initialize($config);
$this->image_lib->resize();
unset($config);
$this->image_lib->clear();
|
|