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 7703391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:26:53+00:00 2026-05-31T23:26:53+00:00

I am trying to upload images and re-size them in different dimensions within the

  • 0

I am trying to upload images and re-size them in different dimensions within the same function. but what happens is that only one re-size works and the others don’t . My code is:

    function do_upload()
{
    $this_user = $this->auth->info;if(!is_dir('./uploads/'.$this_user->username)){
        mkdir('./uploads/'.$this_user->username);
        mkdir('./uploads/'.$this_user->username.'/photos');
        mkdir('./uploads/'.$this_user->username.'/photos/master');
        mkdir('./uploads/'.$this_user->username.'/photos/small');
        mkdir('./uploads/'.$this_user->username.'/photos/medium');
        mkdir('./uploads/'.$this_user->username.'/photos/large');
        mkdir('./uploads/'.$this_user->username.'/photos/xlarge');
    }
    $config['upload_path'] = './uploads/'.$this_user->username.'/photos/master/';
    $config['allowed_types'] = 'gif|jpg';

    $title = $this->input->post('title');
    $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload())
    {
        echo '<div id="status">error</div>';
        echo '<div id="message">'. $this->upload->display_errors() .'</div>';
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());
        //resizing begins
            $image_width = $data['upload_data']['image_width'];
            $image_height = $data['upload_data']['image_height'];
            $full_path = $data['upload_data']['full_path'];
            //checking for width
            if($image_width>5000){
                $config['image_library'] = 'gd2';
                $config['source_image'] = $full_path;
                //$config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 5000;
                //$config['height'] = 50;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/xlarge';
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();
            }
            if($image_width>=4500){
                $config['image_library'] = 'gd2';
                $config['source_image'] = $full_path;
                //$config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 4500;
                //$config['height'] = 50;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/large';
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();
            }
            if($image_width>=2000){
                $config['image_library'] = 'gd2';
                $config['source_image'] = $full_path;
                //$config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 2000;
                //$config['height'] = 50;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/medium';
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();
            }
            if($image_width>=800){
                $config['image_library'] = 'gd2';
                $config['source_image'] = $full_path;
                //$config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 800;
                //$config['height'] = 50;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/small';
                $this->load->library('image_lib', $config);
                $this->image_lib->resize();
            }
        //resizing ends
        echo '<div id="status">success</div>';
        //then output your message (optional)
        echo '<div id="message">'. $data['upload_data']['file_name'].$this->input->post('type').' Successfully uploaded.</div>';
        //pass the data to js
        echo '<div id="upload_data">'. json_encode($data) . '</div>';

    }
}

What Am I doing wrong here?

  • 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-31T23:26:55+00:00Added an answer on May 31, 2026 at 11:26 pm

    You will need to make sure that you call $this->image_lib->clear(); as it resets the initialization of the image manipulation class. See: http://codeigniter.com/user_guide/libraries/image_lib.html

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

Sidebar

Related Questions

I am trying to upload two images, re-size them, and then save them in
I'm trying to upload images to a php file, everything works, but sometimes when
I am trying to upload some images and adding them div container. My question
I'm trying to check an images size in PHP but I'm getting a couple
I am trying to upload some images and display them inside an empty DIV
I'm trying to create a script that would allow the user to upload images
I am trying to upload images on a form but I am using Jquery
Im trying to upload several (one to many) images using grails and jquery. I've
I'm trying to program my application to upload images and then store them in
Recently i have noticed that when i'm trying to upload images to some post

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.