如何使用codeigniter上传超过2mb的文件 [英] how to upload more than 2mb file using codeigniter
问题描述
即使在控制器中设置了最大大小后,我仍试图上传一个大于2mb的文件,但仍然没有上传该文件。请帮助找到解决此问题的方法。
下面是我的代码:
控制器
$ config ['upload_path'] ='./abc/';
$ config [’allowed_types’] =‘*’;
$ config ['max_filename'] ='255';
$ config [’encrypt_name’] =否;
$ 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;
大小限制也由您的PHP配置引起;因此,您需要更新 php.ini
并更新两个设置 post_max_size
和 upload_max_filesize
。
在codeigniter上找不到 php.ini
,而是在服务器上安装了PHP 。在此处了解更多信息: http://php.net/manual/en/configuration。 file.php
假设您要允许最大上传文件大小为256mb,这就是您在 php上应该拥有的大小.ini
:
post_max_size = 256M
upload_max_filesize = 256M
更改为 php.ini
后,您必须重新启动apache或php-fpm-取决于您使用的是什么。
如果您使用共享托管环境,则可能无法直接访问 php.ini
文件,但是您的托管服务提供商可能会限制您通过其托管控制面板(例如cPanel或Plesk等)修改php配置的权限。
如果您是在本地开发的,并说您正在使用XAMPP的Windows上;通常在这里找到 php.ini
文件: C:\xampp\php\php.ini
(取决于您安装xampp的位置)。在Linux上,php.ini配置通常位于 /etc/php.ini
之类的地方(并不总是保证)。
您始终可以使用以下脚本在服务器上创建名为 phpinfo.php
的文件:<?php phpinfo(); ?>
并访问它,例如 http://localhost/phpinfo.php ,它将显示加载的位置 php.ini
文件以及 post_max_size
和 upload_max_filesize
的当前设置值。 / p>
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(); ?>
and visit it, e.g. 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
.
这篇关于如何使用codeigniter上传超过2mb的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!