我正在使用codeIgniter文件上传库来上传文件。一切都很好。但我注意到某些文件没有显示文件上传错误。
我没有上传.pdf文件,但是当我选择一个小的.pdf文件时,#34;您尝试上传的文件类型是不允许的。"错误突然出现。还可以。
但是当我选择更大的(我的文件大小为:24.2 MB).pdf文件并尝试上传该文件时,不会弹出任何错误。
这是我的控制器功能代码:
public function import() {
$import_form_submit = $this->input->post('import_form_submit', TRUE);
if (isset($import_form_submit)) {
$config['upload_path'] = './uploads/temp/';
$config['allowed_types'] = 'gif|jpg|png|csv';
$config['max_size'] = 2048;
$config['remove_spaces'] = TRUE;
$config['detect_mime'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('import_file')) {
$data['import_file_error'] = $this->upload->display_errors('', '');
$data['title'] = 'Import customers';
$data['page_title'] = 'Import customers';
$this->load->view('templates/header', $data);
$this->load->view('templates/main_nav');
$this->load->view('customers/import');
$this->load->view('templates/footer');
} else {
//$data = array('upload_data' => $this->upload->data());
//var_dump($this->upload->data());
//$this->load->view('upload_success', $data);
}
} else {
$data['title'] = 'Import customers';
$data['page_title'] = 'Import customers';
$this->load->view('templates/header', $data);
$this->load->view('templates/main_nav');
$this->load->view('customers/import');
$this->load->view('templates/footer');
}
}
这是我的查看文件代码:
<div class="container">
<div class="row">
<div class="col-md-12">
<?php echo '<h3 class="margin_top_bottom_1rem">'.$page_title.'</h3>'; ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?php
if (isset($import_file_error)) {
echo '<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
'.$import_file_error.'
</div>';
}
?>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form action="<?php echo base_url().'customers/import/'; ?>" method="post" enctype="multipart/form-data">
<fieldset class="form-group">
<label for="import">Choose your .csv file to import.</label>
<input type="file" class="form-control-file" id="import" name="import_file" requiredpp>
<span class="label label-info">Note:</span> <small class="text-muted">Maximum upload file size: 2 MB.</small>
</fieldset>
<button type="submit" class="btn btn-primary" name="import_form_submit"><i class="fa fa-upload" aria-hidden="true"></i> Import .csv file</button>
</form>
</div>
</div>
答案 0 :(得分:0)
将此行$config['allowed_types'] = 'gif|jpg|png|csv';
更改为$config['allowed_types'] = 'gif|jpg|png|csv|pdf';