检查codeigniter文件上载中允许的类型
我想在codeigniter中为我的文件创建多个上载。现在我在检查允许上传的文件类型时遇到了问题。在这里,我的控制器中有一个代码,用于检查数组中的文件是否为图像检查codeigniter文件上载中允许的类型,codeigniter,file-upload,multipartform-data,jquery-file-upload,Codeigniter,File Upload,Multipartform Data,Jquery File Upload,我想在codeigniter中为我的文件创建多个上载。现在我在检查允许上传的文件类型时遇到了问题。在这里,我的控制器中有一个代码,用于检查数组中的文件是否为图像 if(!empty($_FILES['requirement_files']['name'])) { $allowed_types = ['image/jpeg', 'image/jpg', 'image/png']; if(in_array($_FILES['requirement_files']['type'], $
if(!empty($_FILES['requirement_files']['name'])) {
$allowed_types = ['image/jpeg', 'image/jpg', 'image/png'];
if(in_array($_FILES['requirement_files']['type'], $allowed_types)) {
$input_name = "requirement_file";
$upload_path = "../ci_capcims/assets/img/upload/requirements";
$pref = "".date("YmdHis").".";
$paths = multiple_upload($input_name, $upload_path, $pref);
print_r($paths);
}else {
$response['error'] = 'File type not allowed';
$response['success']='false';
header('Content-Type: application/json');
}
}else {
$response['error'] = 'No File/s selected';
$response['success']='false';
header('Content-Type: application/json');
}
echo json_encode($response);
我正在选择一个PNG文件,我被困在返回不允许的文件类型的代码行的条件if(在数组($\u files['requirement\u files']['type'],$allowed\u types)中)
以下是我的观点/表格:
<form method='post' name="frm_attachments" id="frm_attachments_id" enctype="multipart/form-data">
<input type="hidden" name="req_id" id="pre_adopt_child_req_id">
<div class="form-group files">
<label>Upload Your File </label>
<input type="file" class="form-control" name="requirement_files[]" id="file_input" multiple="" required>
</div>
<div class="form-group">
<label for="first_name">Remarks</label>
<textarea class="form-control" rows="4" id="remarks_id" name="remarks" placeholder="Please input remarks here..." style="resize:none;" required></textarea>
</div>
<button type="button" class="btn btn-primary" id="submit_attached_files">Save</button>
</form>
你好,先生,谢谢你的回答。你能定义FCPATH吗;当您希望包含来自根文件夹FCPATH=C:\xampp\htdocs\your\u root\u folder\n的内容时使用,当您希望包含来自应用程序文件夹APPPATH=C:\xampp\htdocs\your\u root\u folder\application\BASEPATH=C:\xampp\htdocs\your\u root\u folder\system的内容时使用\
$(document).on('click', '#submit_attached_files', function(event){
event.preventDefault();
$(":submit").attr("disabled", true);
var fileInput = $('#file_input')[0];
if( fileInput.files.length > 0 ){
var formData = new FormData();
$.each(fileInput.files, function(k,file){
formData.append('requirement_files[]', file);
});
var other_data = $('#frm_attachments_id').serializeArray();
$.each(other_data,function(key,input){
formData.append(input.name,input.value);
});
$.ajax({
method: 'post',
url: baseurl+'user/post/attach_file_in_req',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function(response){
console.log(response);
}
});
}else{
console.log('No Files Selected');
}
});
$this->load->library('upload');
$config=array();
$config['upload_path'] = FCPATH.$save_dir;
$config['allowed_types'] = 'gif|jpg|png|csv';
$config['max_size'] = $this->config->item("max_file_size");
$config['overwrite'] = true;
$config['remove_spaces'] = true;
$uploaded_files=array();
$_FILES['image_profile']['name']=$CurrentUserID.'.jpg';
foreach ($_FILES as $key => $value)
{
if(strlen($value['name'])>0)
{
$this->upload->initialize($config);
if (!$this->upload->do_upload($key))
{
$uploaded_files[$key]=array("status"=>false,"message"=>$value['name'].': '.$this->upload->display_errors());
}
else
{
$uploaded_files[$key]=array("status"=>true,"info"=>$this->upload->data());
}
}
}
return $uploaded_files;