|
楼主 |
发表于 2009-8-29 00:06:21
|
显示全部楼层
本帖最后由 superwf 于 2009-8-29 00:07 编辑
copy文件之后再resize我之前就试过了,以下是测试用的controller
<?php
class Test extends Controller {
public function index()
{
$this->load->view('test');
}
public function upload()
{
$path = './upload/';
$new_path = './upload/thumb';
$config = array(
'allowed_types'=> 'gif|jpg|png|jpeg',
'upload_path'=> $path,
'overwrite'=> false,
'encrypt_name'=> true
);
#echo realpath($path);
#print_r($_FILES);
$this->load->library('upload', $config);
if( $this->upload->do_upload('image') ) {
$file = $this->upload->data();
$temp_file = './upload/temp_'.$file['file_name'];
//生成temp文件
copy($file['full_path'], $temp_file);
//resize原文件
$file_thumb_1 = './upload/thumb_1_'.$file['file_name'];
$config = array(
'image_library' => 'gd2',
'source_image' => $file['full_path'],
'maintain_ratio' => false,
'width' => 150,
'height'=> 150,
'new_image'=> $file_thumb_1
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
//$this->image_lib->clear();
//resize temp文件
$file_thumb_2 = './upload/thumb_2_'.$file['file_name'];
$config = array(
'image_library' => 'gd2',
'source_image' => $file_thumb_1,
'maintain_ratio' => false,
'width' => 50,
'height'=> 50,
'new_image'=> $file_thumb_2
);
$this->load->library('image_lib', $config);
var_dump($this->image_lib->resize());
#echo $this->image_lib->display_errors('<p>', '</p>');
} else {
echo $this->upload->display_errors('<p>', '</p>');
}
}
}
index用的视图
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title> new document </title>
</head>
<body>
<?php echo form_open_multipart('test/upload');?>
<input name="image" type="file" /><br />
<input type="submit" />
</form>
</body>
</html>
第二次resize结果是true,但是没有生成第二个缩略图。不知道还有什么错误,无奈了... |
|