Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter Uploading Large Files

I have set up codeigniter to upload small files < 2MB and that works fine. But I am having trouble uploading large files 20MB >

   function stage1()
    {
    ini_set('upload_max_filesize', '200M');
    ini_set('post_max_size', '200M');                               
    ini_set('max_input_time', 3000);                                
    ini_set('max_execution_time', 3000);

    $config['upload_path'] = './temp/';
    $config['allowed_types'] = 'zip';

    $this->load->library('upload', $config);
    $this->upload->initialize($config);                             
    if(!$this->upload->do_upload('userfile'))                       
    {
      $error = array('error' => $this->upload->display_errors());   
      $this->load->view('upload_form', $error);                     
    }
    else
    {
      $data = array('upload_data' => $this->upload->data());        
      //do stuff
    }
  } 

I am not sure what is wrong with the above code. I overrode the php.ini to accept larger files and to take more time executing the script but it still returns the same error:

You did not select a file to upload.

Again, this works with small files but not large ones.

EDIT: Turns out my server provider has limited file uploads so there is no solution besides to FTP the file in.

like image 909
Kamran224 Avatar asked Sep 18 '12 17:09

Kamran224


People also ask

How to upload Large file in CodeIgniter?

Set config parameter in your stage1 function. $config['max_size'] = '1000000'; $config['max_width'] = '1024000'; $config['max_height'] = '768000'; After then try it.

How to check max file upload size in CodeIgniter?

$config['max_size'] = 2000; set the maximum file size in kilobytes. In our example, the maximum file that can be uploaded is 2,000kb close to 2MB. If the user tries to upload a file larger than 2,000kb, then the image will fail to upload and the library will return an error message.

How do I change the maximum upload size in php INI?

To increaes file upload size in PHP, you need to modify the upload_max_filesize and post_max_size variable's in your php. ini file. In addition, you can also set the maximum number of files allowed to be uploaded simultaneously, in a single request, using the max_file_uploads . Note that from PHP 5.3.


2 Answers

Below code use in your php file.

ini_set( 'memory_limit', '200M' );
ini_set('upload_max_filesize', '200M');  
ini_set('post_max_size', '200M');  
ini_set('max_input_time', 3600);  
ini_set('max_execution_time', 3600);

set below code in .htaccess file

php_value upload_max_filesize 128M  
php_value post_max_size 128M  
php_value max_input_time 3600  
php_value max_execution_time 3600

Edit my answer after you comment

Update answer

Set config parameter in your stage1 function.

$config['max_size'] = '1000000';
$config['max_width']  = '1024000';
$config['max_height']  = '768000';

After then try it.

like image 183
Abid Hussain Avatar answered Oct 18 '22 23:10

Abid Hussain


I'm not sure your server accept the ini "upload_max_filesize" property to be modified wit hphp script. By default it can't according to the documentation http://php.net/manual/fr/ini.core.php .

upload_max_filesize | "2M" | PHP_INI_PERDIR | PHP_INI_ALL pour PHP <= 4.2.3.

PHP_INI_PERDIR means that it must be writen in your ini file directly. If you have no controle over php.ini, you will not be able to override this property.

like image 1
artragis Avatar answered Oct 19 '22 00:10

artragis