0

I'm setting up the upload file before add resize code. And its normally process, but after adding resize code my controller isn't working. Can you help me with this? I'm trying but it didn't work.

And my another problem, I can't upload image file size more than 2MB.

This for my work on online shop.

public function submit_image()
{
    $input_name = $_POST['input_name'];
    $input_email = $_POST['input_email'];
    $input_code_transaction = $_POST['input_code_transaction'];

    $config['file_name'] = $input_code_transaction;
    $config['overwrite'] = TRUE;
    $config['upload_path']          = './img/';
    $config['allowed_types']        = 'gif|jpg|png|jpeg';
    $config['max_size']             = 50000000;
    $config['max_width']            = 6000;
    $config['max_height']           = 4000;

    $this->upload->initialize($config);

    if(!empty($_FILES['filefoto']['name'])) {
        if ($this->upload->do_upload('doc')) {
            $gbr = $this->upload->data();
            //Compress Image
            $config['image_library']='gd2';
            $config['source_image']='./img/'.$gbr['file_name'];
            $config['create_thumb']= FALSE;
            $config['maintain_ratio']= FALSE;
            $config['quality']= '50%';
            $config['width']= 1280;
            $config['height']= 720;
            $config['new_image']= './img/'.$gbr['file_name'];
    $this->load->library('upload', $config);
            $this->upload->resize();        

    $data = $upload_data = $this->upload->data();
    $input_picture = $this->upload->do_upload('doc');
                }
        }
 }
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • The 2MB file upload is a setting in the php.config you need to change the upload_max_filesize and post_max_size limits. – Richard Housham Jul 15 '19 at 09:10
  • And I suppose gd2 is not installed or activated on your server (localhost) – Vincent Decaux Jul 15 '19 at 09:11
  • when you say stopped working, have you an error message? https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings/5438125 – Richard Housham Jul 15 '19 at 09:12
  • wait im check this, and for error message no i didnt have just blank white screen @RichardHousham –  Jul 15 '19 at 09:16
  • where to activate gd2 on CodeIgniter? @VincentDecaux –  Jul 15 '19 at 09:17
  • gd2 is a module that you have to add to php. You normally do it on install, but you can activate it later. Google "gd2 php and whatever operating system you are using" – Richard Housham Jul 15 '19 at 09:19
  • Regards the error have you checked your error log php_error.log – Richard Housham Jul 15 '19 at 09:21
  • im done with upload max 2MB, but for gd2 i didnt find it to activated or install. and how i do to check this gd2 on or off in my php setting? @RichardHousham –  Jul 15 '19 at 09:42
  • create a page with the code that will show you all your php settings. – Richard Housham Jul 15 '19 at 10:22
  • did you set upload_max_filesize? if you use linux ubuntu, u can find in /etc/php/5.6/apache2/php.ini and found upload_max_filesize, default is 2 MB – Hip Hura Jul 15 '19 at 10:32
  • you all are missing the fact OP is trying to resize using the upload library not the image lib library – Alex Jul 15 '19 at 22:04
  • thanks for info, but im done for max file upload :D @HipHura –  Jul 16 '19 at 01:11

1 Answers1

0

The upload library has no inbuilt features for image resizing.

This whole section:

$config['image_library']='gd2';
            $config['source_image']='./img/'.$gbr['file_name'];
            $config['create_thumb']= FALSE;
            $config['maintain_ratio']= FALSE;
            $config['quality']= '50%';
            $config['width']= 1280;
            $config['height']= 720;
            $config['new_image']= './img/'.$gbr['file_name'];
    $this->load->library('upload', $config);
            $this->upload->resize();        

    $data = $upload_data = $this->upload->data();
    $input_gambar = $this->upload->do_upload('doc');

needs to reference image_lib the image resizer codeigniter uses: https://www.codeigniter.com/user_guide/libraries/image_lib.html

So:

    if ($this->upload->do_upload('doc')) {
        $gbr = $this->upload->data();
        //Compress Image


        $imlib['image_library'] = 'gd2';
        $imlib['source_image'] = './img/' . $gbr['file_name'];
        $imlib['create_thumb'] = FALSE;
        $imlib['maintain_ratio'] = FALSE;
        $imlib['quality'] = '50%';
        $imlib['width'] = 1280;
        $imlib['height'] = 720;
        $imlib['new_image'] = './img/resized_' . $gbr['file_name'];
        $this->load->library('image_lib', $imlib);
        if (!$this->image_lib->resize()) {
            show_error($this->image_lib->display_errors());
        }
        $yourouputimage = './img/resized_' . $gbr['file_name'];
    }
Alex
  • 9,215
  • 8
  • 39
  • 82
  • Okay, i will try this broo –  Jul 16 '19 at 01:11
  • why when i input this code, my proccess page HTTP ERROR 500? im using php with framework codeigniter :( @Alex –  Jul 16 '19 at 02:23
  • turn on error reporting. in index.php make sure environment is development. without an exact error it is impossible to tell what is going wrong. – Alex Jul 16 '19 at 07:52
  • you don't post an answer if that answer is asking another question. you accept an answer if it answered your specific question, and then you ask a new question otherwise this site would be chaos – Alex Jul 16 '19 at 09:23
  • im sorry, i will fix it –  Jul 16 '19 at 09:27