Codeigniter 缩略图数组不起作用
Codeigniter thumbnail array not working
我正在上传多个文件,工作正常。
我得到了两个图像,但另一个图像是缩略图,没有得到它们的给定路径,也没有改变为缩略图大小。
我希望 "thumbnail creation start" 区域的缩略图有问题。
检查我的阵列,让我知道我的错误。
控制器代码
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $image['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 150;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
$this->upload->do_upload();
$data = $this->upload->data();
$name_array1[] = $data['file_name']; // file names for thumb
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function
在你对你的图像进行配置后,即设置你的图像属性,然后你应该清除并初始化 image_lib
才能生效。
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
注:
确保 $config
或 $config1
需要它
确保 source_image
路径正确
替换
$config1['source_image'] = $image['full_path'];
至
$config1['source_image'] = $data['full_path'];
同时删除以下注释行
$this->image_lib->resize();
//$this->upload->do_upload();
//$data = $this->upload->data();
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $data['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 500;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->clear();
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$name_array1[] = $data['file_name']; // get file names for thumb file
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function
我正在上传多个文件,工作正常。 我得到了两个图像,但另一个图像是缩略图,没有得到它们的给定路径,也没有改变为缩略图大小。
我希望 "thumbnail creation start" 区域的缩略图有问题。 检查我的阵列,让我知道我的错误。
控制器代码
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $image['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 150;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
$this->upload->do_upload();
$data = $this->upload->data();
$name_array1[] = $data['file_name']; // file names for thumb
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function
在你对你的图像进行配置后,即设置你的图像属性,然后你应该清除并初始化 image_lib
才能生效。
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
注:
确保
$config
或$config1
需要它
确保
source_image
路径正确
替换
$config1['source_image'] = $image['full_path'];
至
$config1['source_image'] = $data['full_path'];
同时删除以下注释行
$this->image_lib->resize();
//$this->upload->do_upload();
//$data = $this->upload->data();
public function addimage($room_id)
{
$name_array = array();
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key=>$value)
for($s=0; $s<=$count-1; $s++)
{
$_FILES['userfile']['name']=$value['name'][$s];
$_FILES['userfile']['type'] = $value['type'][$s];
$_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
$_FILES['userfile']['error'] = $value['error'][$s];
$_FILES['userfile']['size'] = $value['size'][$s];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
$name_array[] = $data['file_name']; // get file names for first file
//thumbnail creation start
$config1['image_library'] = 'gd2';
$config1['source_image'] = $data['full_path'];
$config1['create_thumb'] = TRUE;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config1['maintain_ratio'] = TRUE;
$config1['upload_path'] = './uploads/thumbs/';
$config1['width'] = 500;
$config1['height'] = 150;
$this->load->library('image_lib', $config1);
$this->image_lib->clear();
$this->image_lib->initialize($config1);
$this->image_lib->resize();
$name_array1[] = $data['file_name']; // get file names for thumb file
//thumbnail creation end
}
$names= implode(',', $name_array);
$names2= implode(',', $name_array1);
//print_r($names);
$options = array(
'id' => '0',
'org_image' => $names,
'thumbnail' => $names2,
'room_id' => $room_id,
'created' => '1',
'status' => '1'
);
$this->rooms_model->room_images_insert($options);
redirect('/admin/rooms', 'location');
} //end of function