Welcome Guest, Not a member yet? Register   Sign In
Unexpected issue with file uploads in CodeIgniter 3
#1

Hi....

I have 2 websites created with CodeIgniter on the same host. I've been using them without any issues for the past 3 years. I have several forms in various places for uploading images, using only PHP without AJAX and jQuery. When the file is uploaded without errors, it redirects to the same form page. This functionality has been working perfectly all these years.
Suddenly, 10 days ago, when I upload an image, the spinner on the browser tab freezes and keeps spinning as if it's still loading, even though the file has already been uploaded. It seems to hang just before the redirection. The file is in the folder, and the database record has been created.
If I refresh the page at that moment, the next file I upload works perfectly with the redirection, etc.
The strange thing is that I haven't made any changes to the page, PHP, MySQL, or anywhere else. I asked the host if there were any changes or upgrades, and they said no. I don't know where to look for the issue.
The problem is in Google chrome. I make some test in firefox and i think is work fine in firefox
Below, let's take a look at a snippet of the upload code I mentioned.

Code:
function upload_tameia_photos(){
    $time= time();
    $mt_rand = mt_rand(100,999);
    $id = $_POST["tameia_id"];

    $year = date('Y');

    $config['upload_path'] = './assets/img-tameia';
    $config['allowed_types'] = 'gif|jpg|png';
    //$config['encrypt_name'] = true;
    $config['max_size'] = '6048';
    $config['max_width'] = '8000';
    $config['max_height'] = '6000';
    $config['file_name'] = $year.'-'.$id.'-'.$mt_rand.$time;
    $this->load->library('upload', $config);
    $data['title'] = "Upload Files";
   
    if (!$this->upload->do_upload('photos')) {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('templates/header', $data);
        $this->load->view('tameio_photo', $error);
        $this->load->view('templates/footer');
    } else {
        $imgName = $this->upload->data();
       
        $config['image_library'] = 'gd2';
        $config['source_image'] = './assets/img-tameia/'.$imgName["file_name"];
        $config['maintain_ratio'] = TRUE;
        $config['quality'] = '80%';
        $config['width'] = 1000;
        $config['new_image'] = './assets/img-tameia/'.$imgName["file_name"];
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
       
        $imgurl = $imgName["file_name"];
        $data = array(
            'ph_tameio_id'  => $id,
            'ph_tameia_url'  => $imgurl
        );

        $this->db->insert('phot_tameia', $data);
    }

    redirect(base_url().'reports/tameio_view/'.$id);
}
Reply
#2

image manipulation library ($this->image_lib) might not be properly configured before calling the resize() method? Ensure that all required configuration parameters are set correctly before resizing the image.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB