Я создал вспомогательную функцию, вызывающую функцию для каждого файла.По сути, функция проверяет, является ли загруженный файл pdf / xlsx, но функция ничего не возвращает в качестве результата.Я не мог понять, где находится ошибка.
Мой контроллер
class Bike_insurance_brochure extends CI_Controller {
function __construct(){
parent::__construct();
if(!is_admin_logged_in())
redirect("/admin","refresh",301);
$this->load->model('admin/bike_insurance_brochure_m');
}
function index(){
$this->load->admin_template('bike_insurance_brochure_view');
}
function save(){
$config=array(
array(
'field'=>'product_b',
'label'=>'Product Brochure',
'rules'=>'trim|callback_check_brochure'
),
array(
'field'=>'product_w',
'label'=>'Policy Wordings',
'rules'=>'trim|callback_check_word'
),
array(
'field'=>'product_c',
'label'=>'Policy Claim',
'rules'=>'trim|callback_check_claim'
),
array(
'field'=>'company',
'label'=>'company',
'rules'=>'trim|max_length[255]'
),
array(
'field'=>'product',
'label'=>'product',
'rules'=>'trim|required'
)
);
$this->form_validation->set_rules($config);
if($this->form_validation->run()!==FALSE){
print_r(json_encode($this->bike_insurance_brochure_m->save()));
}
else{
$error= "<ul>";
$error.= validation_errors("<li>", "</li>");
$error.= "</ul>";
print_r(json_encode(['status'=>'false','message'=>$error]));
}
}
function get_product_details($bike_insu_bro_id=NULL){
if($bike_insu_bro_id==NULL || trim($bike_insu_bro_id)==""){
print_r(json_encode(['status'=>'false','message'=>'Invalid record selected']));
}
print_r(json_encode($this->bike_insurance_brochure_m->get_product_details($bike_insu_bro_id)));
}
function update_details($bike_insu_bro_id){
$config=array(
array(
'field'=>'product_b',
'label'=>'Product Brochure',
'rules'=>'trim|callback_check_brochure'
),
array(
'field'=>'product_w',
'label'=>'Policy Wordings',
'rules'=>'trim|callback_check_word'
),
array(
'field'=>'product_c',
'label'=>'Policy Claim',
'rules'=>'trim|callback_check_claim'
),
array(
'field'=>'company',
'label'=>'company',
'rules'=>'trim|max_length[255]'
),
array(
'field'=>'product',
'label'=>'product',
'rules'=>'trim|required'
)
);
$this->form_validation->set_rules($config);
if($this->form_validation->run()!==FALSE){
print_r(json_encode($this->bike_insurance_brochure_m->update_details($bike_insu_bro_id)));
}
else{
$error= "<ul>";
$error.= validation_errors("<li>", "</li>");
$error.= "</ul>";
print_r(json_encode(['status'=>'false','message'=>$error]));
}
}
function delete($bike_insu_bro_id=NULL){
if($bike_insu_bro_id==NULL || trim($bike_insu_bro_id)==""){
print_r(json_encode(['status'=>'false','message'=>'Invalid record selected']));
}
print_r(json_encode($this->bike_insurance_brochure_m->delete($bike_insu_bro_id)));
}
function get_bike_insurance_brochure_list($page=1){
$this->load->library('pagination');
$this->load->library('paginationlib');
try
{
$pagingConfig = $this->paginationlib->initPagination($this->bike_insurance_brochure_m->record_count());
$list = $this->bike_insurance_brochure_m->get_bike_insurance_brochure_list((($page-1) * $pagingConfig['per_page']),$pagingConfig['per_page']);
$list["pagination"] = $this->pagination->create_links();
$list['index_start']=(50*($page-1))+1;
print_r($this->load->view('admin/ajax/bike_insurance_brochure_list',$list,TRUE));
}
catch (Exception $err){}
}
function get_bike_product_list(){
print_r(json_encode($this->bike_insurance_brochure_m->get_product_list($this->input->post('company'))));
}
function check_brochure(){
check_brochure($this->input->post('product_b'));
}
function check_word(){
check_word($this->input->post('product_w'));
}
function check_claim(){
check_claim($this->input->post('product_c'));
}
}
Пользовательская вспомогательная функция
if (!function_exists('check_brochure'))
{
function check_brochure($product_brochure){
$CI =& get_instance();
$allowed_mime_type_arr = array("application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/pdf","application/msword");
$mime_brochure = get_mime_by_extension($product_brochure);
if(isset($product_brochure) && $product_brochure !=""){
if(in_array($mime_brochure, $allowed_mime_type_arr)){
echo 'hi';
return true;
}else{
$CI->form_validation->set_message('check_brochure', 'Please select only .pdf/.docx/.doc Product Brochure.');
echo 'ye';
return false;
}
}else{
$CI->form_validation->set_message('check_brochure', 'Please choose a file to upload Product Brochure.');
echo 'bye';
return false;
}
}
}
Он возвращает пока при проверке, но функция невернитесь к ложному, я имею в виду сообщение об ошибке не отображается.Мой autoload.php:
$autoload['helper'] = array('url', 'file','form','email_settings','comm_func','html','string','globals');