简体   繁体   中英

how to upload more than 2mb file using codeigniter

I am trying uploading a file which is more than 2mb even after setting maximum size in controller but still the file is not getting uploaded.please help to find the solution for this problem.

Below is my code:

Controller

    $config['upload_path'] = './abc/';
    $config['allowed_types'] = '*';
    $config['max_filename'] = '255';
    $config['encrypt_name'] = FALSE;
    $config['overwrite'] = TRUE;
    //$config['max_size'] = '102400'; //100 MB
    $config['max_size']             = '25600';
    $config['max_width']            = '0';
    $config['max_height']           = '0';
    $config['file_name']=$newfilename;

The size limitation is imposed by your PHP configuration also; therefore you need to update php.ini and update two settings post_max_size and upload_max_filesize .

The php.ini is not found on codeigniter, rather the PHP installation on your server. Read more about it here: http://php.net/manual/en/configuration.file.php

Say you want to allow a max upload file size of 256mb, this is what you should have on the php.ini :

post_max_size=256M
upload_max_filesize=256M

Once you made the change to php.ini , you have to restart the apache or php-fpm - depending on what you are using.

If you are on a shared hosting environment, you may not get direct access to the php.ini file, but your hosting provider may give you limited access to modify php configuration via their hosting control panel such as cPanel or Plesk etc...

If you developing locally, and say you are on windows using XAMPP for example; the php.ini file is usually found here: C:\\xampp\\php\\php.ini (depends on where you've installed xampp). On linux, the php.ini configuration tends to be somewhere like /etc/php.ini (not always guranteed).

You could always create a file on your server called phpinfo.php with this script: <?php phpinfo(); ?> <?php phpinfo(); ?> and visit it, eg http://localhost/phpinfo.php and it will show you the location the loaded php.ini file as well as the current setting values of post_max_size and upload_max_filesize .

You can change your .htaccess file in the root folder of your CI project. This is good for shared hosting where you may not change php.ini):

## I need more memory (50M) to upload large image
<IfModule mod_php5.c>
  php_value memory_limit 256M
  php_value post_max_size 50M
  php_value upload_max_filesize 50M
</IfModule>

in Codeigniter you set filesize preferences in your config.php file: see docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM