在CodeIgniter中上传特定宽度和高度的图片,可以通过以下步骤实现:
$this->load->library('upload');
$this->load->library('image_lib');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 2048;
$this->upload->initialize($config);
if (!$this->upload->do_upload('image')) {
$error = $this->upload->display_errors();
// 处理上传失败的情况
} else {
$data = $this->upload->data();
$image_path = $data['full_path'];
// 处理上传成功的情况
}
$this->image_lib->clear();
$this->image_lib->initialize(array('image_library' => 'gd2'));
$config['source_image'] = $image_path;
$config['new_image'] = './uploads/resized/';
$config['maintain_ratio'] = TRUE;
$config['width'] = $desired_width;
$config['height'] = $desired_height;
$this->image_lib->initialize($config);
if (!$this->image_lib->resize()) {
$error = $this->image_lib->display_errors();
// 处理调整尺寸失败的情况
} else {
$resized_image_path = $config['new_image'] . $data['file_name'];
// 处理调整尺寸成功的情况
}
以上步骤中,$desired_width
和$desired_height
是从表单中获取的特定宽度和高度的值。
在CodeIgniter中,可以使用以下相关功能和类来实现这个功能:
$this->load->library('upload')
$this->load->library('image_lib')
推荐的腾讯云相关产品:腾讯云对象存储(COS)
领取专属 10元无门槛券
手把手带您无忧上云