Archive for 十二月, 2008

在Codeigniter中为上传文件指定名字

CI的Upload类不能在上传之前给文件指定名字,在官方论坛找到一个朋友提供的MY_Upload类,该类解决了上传文件不能先指定名字的问题。
使用方法如下:

$config['upload_filename'] = $upload_filename;
$config['upload_path'] = $upload_path;
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '2000';
$config['max_width'] = '200';
$config['max_height'] = '200';
$this->load->library('upload', $config);

其实就是增加了一个upload_filename字段来做为指定的名字 :razz:

在Codeigniter中生成png透明缩略图

CI中的CI_Image_lib类不能生成背景透明的png或gif缩略图,以下是我的解决办法,重新创建一个MY_Image_lib类,并继承CI_Image_lib类,然后重写一下image_process_gd方法。

先在CI_Image_lib中找到image_process_gd方法,然后把这个方法的全部代码复制到MY_Image_lib类中,然后查找下面这行代码:

$dst_img = $create($this->width, $this->height);

接着在找到的这行代码下面添加如下代码:

$transparent = imagecolortransparent($src_img, imagecolorallocate($src_img, 0, 0, 0));
if ($transparent >= 0) {
	imagecolortransparent($dst_img, $transparent);
	imagealphablending($dst_img, false);
	imagesavealpha($dst_img, true);
}
Powered by WordPress | Shop Free Cellular Phones at Bestincellphones.com. | Thanks to Best CD Rates, iCellPhoneDeals.com Offers Best Cell Phone Deals. and Incinerador De Grasa