CodeIgniter上传大文件 [英] CodeIgniter Uploading Large Files
问题描述
我设置了codeigniter来上传小文件< 2MB,工作正常。但是我无法上传大文件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-> > display_errors());
$ this-> load-> view('upload_form',$ error);
}
else
{
$ data = array('upload_data'=> $ this-> upload-> data());
// do stuff
}
}
肯定上面的代码有什么问题。我超越了php.ini接受更大的文件,并采取更多的时间执行脚本,但它仍然返回相同的错误:
您没有选择要上传的文件。
同样,这适用于小文件,但不适用于大文件。
编辑:结果我的服务器提供商有限的文件上传,所以除了FTP之外没有解决方案。
以下代码用于您的PHP文件。
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);
在.htaccess文件中设置以下代码 b
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_input_time 3600
php_value max_execution_time 3600
在您注释后编辑我的答案
更新答案
在stage1函数中设置配置参数。
$ config ['max_size'] ='1000000';
$ config ['max_width'] ='1024000';
$ config ['max_height'] ='768000';
然后尝试。
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.
解决方案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.
这篇关于CodeIgniter上传大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!