作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试上传图片并调整它们的大小,到目前为止上传工作正常,并且还创建了缩略图图像。但是我无法调整原始图像的大小。所发生的只是文件以其原始大小直接上传到文件夹中。我想我正在尝试调整此图像的大小,然后覆盖最初上传的文件。
这是我的代码,我缺少什么:
//Initialise the upload file class
$config['upload_path'] = './image_uploads/';
$config['allowed_types'] = 'jpg|jpeg|gif|png';
$config['max_size'] = '6048';
$this->load->library('upload', $config);
$userfile = "_upload_image";
//check if a file is being uploaded
if(strlen($_FILES["_upload_image"]["name"])>0){
if ( !$this->upload->do_upload($userfile))//Check if upload is unsuccessful
{
$upload_errors = $this->upload->display_errors('', '');
$this->session->set_flashdata('errors', 'Error: '.$upload_errors);
redirect('admin/view_food/'.$food->course_id);
}
else
{
//$image_data = $this->upload->data();
////[ THUMB IMAGE ]
$config2['image_library'] = 'gd2';
$config2['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config2['new_image'] = './image_uploads/thumbs';
$config2['maintain_ratio'] = TRUE;
$config2['create_thumb'] = TRUE;
$config2['thumb_marker'] = '_thumb';
$config2['width'] = 75;
$config2['height'] = 50;
$this->load->library('image_lib',$config2);
if ( !$this->image_lib->resize()){
$this->session->set_flashdata('errors', $this->image_lib->display_errors('', ''));
}
//[ MAIN IMAGE ]
$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
//$config['new_image'] = './image_uploads/';
$config['maintain_ratio'] = TRUE;
$config['width'] = 250;
$config['height'] = 250;
$this->load->library('image_lib',$config);
if ( !$this->image_lib->resize()){
$this->session->set_flashdata('errors', $this->image_lib->display_errors('', ''));
}
}
}
最佳答案
您是否尝试将其添加到配置选项中
$config['overwrite'] = TRUE;
这应该可以解决问题。
根据文档
If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the>same name exists.
关于php - CodeIgniter 上传图片然后调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10027083/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!