php – CodeIgniter上传图片然后调整大小

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – CodeIgniter上传图片然后调整大小脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试上传图片调整它们的大小,到目前为止上传工作还有拇指指甲图像的创建.但我不能让原始图像调整大小.所有发生的事情是文件以原始大小直接上传文件夹.我想我正在尝试将此图像调整大小然后覆盖最初上传文件.

这是我的代码,我错过了什么:

//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',''));   
              }
               }      
           }
是否尝试将此添加到配置选项中
$config['overwrite'] = TRUE;

应该可以解决问题.

根据文件

脚本宝典总结

以上是脚本宝典为你收集整理的php – CodeIgniter上传图片然后调整大小全部内容,希望文章能够帮你解决php – CodeIgniter上传图片然后调整大小所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。