<form id="new_goods" name="new_goods" method="post" action="<?php echo $baseurl;?>admin/goods/add_goods/" enctype="multipart/form-data">
<p style="margin-bottom:5px;">
信息图片:<input type="file" name="pic" size="40" /> (仅限JPG和PNG格式,大小不超过1024x768像素,体积不超过300K.)</p>
</form>
goods.php
function add_goods() {
$config['upload_path'] = './public/data/goods_images/full/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '300';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['encrypt_name']='TRUE';
$this->load->library('upload', $config);
if (!$this->upload->do_upload('pic')) {
//如果图片没有成功上传,则报错
$this->admin_model->info(4,'抱歉,图片上传失败。可能您选择的图片大小超出了限制。请返回重新上传。','back');
// echo $this->upload->display_errors();
}
else {
$data = array('upload_data' => $this->upload->data()); //上传文件信息
$imgname=$data['upload_data']['file_name']; //上传后的文件名(包括扩展名)
$this->load->library('image_lib');
$config['image_library'] = 'GD2';
$config['source_image'] = "public/data/goods_images/full/{$imgname}";
$config['new_image'] = "public/data/goods_images/thumb/{$imgname}";
$config['width'] = 100;
$config['height'] = 100;
$config['quality']='90%';
$this->image_lib->initialize($config);
$this->image_lib->resize(); //生成缩略图
$goods_data['pic']='full/'.$imgname; //新闻完整图片路径
$goods_data['shortpic']='thumb/'.$imgname;//新闻缩略图路径
} |