Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:12:46+00:00 2026-05-26T18:12:46+00:00

I’m trying to have a user upload a file and then my function will

  • 0

I’m trying to have a user upload a file and then my function will resize that photo to something like 800×600 and then resize that file to 165×165. With my code, it’s only resizing it to 165×165, but if I comment that section out, it resizes it to 800×600.

What can I do to get it to resize both?

   /**
    * addPhoto - function which shows the add photo page
    */
    function addPhoto($album)
    {   
        $album = rawurldecode($album);

        ini_set('upload_max_filesize', '4M');  
        ini_set('post_max_size', '12M');  
        ini_set('max_input_time', 300);  
        ini_set('max_execution_time', 300); 

        $config['upload_path'] = './assets/images/photoAlbums/'.$album.'/';
        $config['allowed_types'] = 'jpg|jpeg|pjpeg';
        $config['max_size'] = '4096';   // that's 4MBs
        $config['max_width'] = '4000';
        $config['max_height'] = '3000';
        $config['remove_space'] = TRUE;
        $config['overwrite'] = TRUE;

        $this->load->library('upload', $config);

        if(!$this->upload->do_upload('userFile')) { // if there are errors uploading the file...
            $content_data['error'] = array('error' => $this->upload->display_errors());


        } else {    // else there are NO errors, we need to resize it, and ditch that huge ass original


        $image = $this->upload->data(); 
        $uploadedFile = $image['file_name'];

        $this->load->library('image_lib');

        $thumbConfig['image_library'] = 'gd2';
            $thumbConfig['source_image'] = $image['full_path']; 
        $thumbConfig['create_thumb'] = FALSE;
        $thumbConfig['maintain_ratio'] = TRUE;
        $thumbConfig['width'] = 800;
        $thumbConfig['height'] = 600;

        $this->image_lib->initialize($thumbConfig);

        if ( ! $this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        }

        $this->image_lib->clear();

        $thumbConfig['image_library'] = 'gd2';
        $thumbConfig['source_image'] = $image['full_path'];
        $thumbConfig['create_thumb'] = TRUE;
        $thumbConfig['maintain_ratio'] = FALSE;
        $thumbConfig['width'] = 165;
        $thumbConfig['height'] = 165;

        $this->image_lib->initialize($thumbConfig);

        if ( ! $this->image_lib->resize())
        {
            echo $this->image_lib->display_errors();
        }

        $content_data['firstName'] = $this->session->userdata('firstName');
        $data['sess'] = $this->session;
        $data['content'] = $this->load->view('member/addPhoto_success', $content_data, true);
        $this->load->view('template/admin', $data);
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:12:47+00:00Added an answer on May 26, 2026 at 6:12 pm

    for the second time running the image_lib, you’re going to want to avoid overwriting the file by specifying the new file for it to create:
    after:

    $thumbConfig['height'] = 165;
    

    add:

    $thumbConfig['new_image'] = $image['file_path'] . "thumb_" . $image['file_name'];
    

    so if your resized 800 x 600 image resides at /my/upload/path/foo.jpg,
    this will create a thumb at /my/upload/path/thumb_foo.jpg.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.