我有一个codeigniter应用程序,它基本上接受xls
个文件,解析它并处理来自excel文件的数据。
以下是我用于上传文件的代码。
提交表单后,将执行以下代码。当我提交小尺寸的文件时,它会正确上传并进行处理。但是,如果我上传的文件较大,则会上传,但不会处理。我甚至被重定向到上传表单时出现错误“您没有选择要上传的文件。”
这是由max_execution_time
引起的吗?
PS:我在控制器的顶部有这三行
set_time_limit(0);
ini_set('memory_limit', '20000M');
ini_set('max_execution_time', 3000);
更新: 我想要更新的文件大小是1.59 MB
上传
public function do_upload() {
$config['upload_path'] = './excel_files/';
$config['allowed_types'] = 'xls|xlsx';
$config['max_size'] = 100000;
$this->load->library('upload', $config);
// upload failed, handle properly
if ( ! $this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$data = array('subview'=>'admin/upload_form','error'=>$error);
$this->load->view('layout', $data);
}
// upload success, record the file data
else {
$uploadData = $this->upload->data();
$fileData = array(
'name' => $uploadData['orig_name'],
'size' => $uploadData['file_size'],
'stored_name' => $uploadData['file_name'],
);
$this->file_m->insert($fileData);
$this->process($uploadData); // process the uploaded file
}
}
答案 0 :(得分:2)
它看起来重写代码无效。
set_time_limit(0);
ini_set('memory_limit', '20000M');
ini_set('max_execution_time', 3000);
方式1:
更新php.ini文件中的设置。希望问题将得到解决。
max_execution_time = 259200
max_input_time = 259200
memory_limit = 300M
upload_max_filesize = 200M
post_max_size = 200M
方式2:
.htaccess
方式
<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>
通过创建php信息文件来验证设置。
test_settings.php
<?php
phpinfo();
?>
答案 1 :(得分:1)
function upload_it() {
//load the helper
$this->load->helper('form');
$config['upload_path'] = 'application/views/uploads/';
// set the filter image types
$config['allowed_types'] = 'xls|xlsx';
//load the upload library
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('*');
$data['upload_data'] = '';
//if not successful, set the error message
if (!$this->upload->do_upload('userfile')) {
$data = array('msg' => $this->upload->display_errors());
} else { //else, set the success message
$data = array('msg' => "Upload success!");
$data['upload_data'] = $this->upload->data();
}
//load the view/upload.php
$this->load->view('upload', $data);
}