Search code examples
phpcodeigniterzip

Download Zip file corrupted in codeigniter


I'm using this function to create and download ZIP files. It works well for less than 200MB files, I tested. When I tried to download More than 250MB files then download stops partially and while opening it shows corrupted.

    public function download_songs($bs_id){
    // public function download_songs(){
    $this->load->library('zip');
    $this->load->helper('file');
    $this->load->helper('download');
    // $bs_id       = $this->input->post('bs_id');

    $bsl_data       = $this->public_model->get_result_array_with_one_where('buy_song_list','psl_bs_id',$bs_id);
    $bal_data       = $this->public_model->get_result_array_with_one_where('buy_album_list','bal_bs_id',$bs_id);

    $d_type = 0;
    foreach($bsl_data as $bs_row){
        $dateA = $bs_row['psl_created']; 
        // your second date coming from a mysql database (date fields) 
        date_default_timezone_set('Asia/Kolkata');
        $dateB = date("Y-m-d H:i:s"); 

        $timediff = strtotime($dateB) - strtotime($dateA);

        //if($timediff>10800){ // echo 'more than 3 hours';
        if($timediff > 86400){  //echo 'more than 24 hours';
            $this->db->where('psl_mml_id',$bs_row['psl_mml_id'])
                    ->set('psl_status','1')
                    ->update('buy_song_list');
            $d_type = 0;
        }
        else{
            // echo 'less than 3 hours';            
            if($bs_row['psl_status']=='0'){                 
                $mml_data = $this->public_model->get_result_array('music_mp3_list','','','mml_id',$bs_row['psl_mml_id']);                   
                if($bs_row['psl_file_type']=='MP3'){
                    $f = $mml_data['mml_mp3'];
                }
                if($bs_row['psl_file_type']=='MP4'){
                     $f = $mml_data['mml_mp4'];
                }                   
                $ex_p = explode('?',$f);
                $path = "public_html/upload/music_mp3/".$ex_p[0];
                $this->zip->read_file($path);
                $d_type = 1;    
            }else{
                $d_type = 0;
            }
        }
    }

    foreach($bal_data as $ba_row){
        $dateA = $ba_row['bal_created']; 
        // your second date coming from a mysql database (date fields) 
        date_default_timezone_set('Asia/Kolkata');
        $dateB = date("Y-m-d H:i:s"); 

        $timediff = strtotime($dateB) - strtotime($dateA);

        // if($timediff > 10800){ //echo 'more than 3 hours';
        if($timediff > 86400){  //echo 'more than 24 hours';

            $this->db->where('bal_mal_id',$ba_row['bal_mal_id'])
                        ->set('bal_status','1')
                        ->update('buy_album_list');
            $d_type = 0;
        }
        else{
            if($ba_row['bal_status']=='0'){             
                $mal_mml_data = $this->public_model->get_result_array_with_one_where('music_mp3_list','mml_mal_id',$ba_row['bal_mal_id']);
                foreach($mal_mml_data as $re_row){
                    if($ba_row['bal_file_type']=='MP3'){
                        $f = $re_row['mml_mp3'];
                    }
                    if($ba_row['bal_file_type']=='MP4'){
                        $f = $re_row['mml_mp4'];
                    }

                    if($ba_row['bal_file_type']=='full_album'){
                        $f = $re_row['mml_mp3'];
                    }

                    $ex_p = explode('?',$f);
                    $path = "public_html/upload/music_mp3/".$ex_p[0];
                    $this->zip->read_file($path);
                    $d_type = 1;
                }   
            }else{
                $d_type = 0;
            }
        }
    }
    if($d_type=='1'){
        ob_end_clean();
        $zip_f_name = 'gravity_'.date('Y_m_d_His').'.zip';
        $this->zip->download($zip_f_name);
    }else{
        $data['waring_msg'] = 'Sorry this file already downloaded.';
        $this->load->view('paypal_status',$data);

    }

}

Also used function ob_end_clean(); from earlier questions but still issue persists


Solution

  • The Hosting provider limiting the size of files that can be generated.