如何在codeigniter中上载php或html文件?

如何在codeigniter中上载php或html文件?,codeigniter,Codeigniter,如何使用上载库在codeigniter中上载php或html文件?我有一个控制器,它在上传jpg、gif、png文件时可以正常工作,但上传带有php、html或sql扩展名的文件时却不能正常工作 这是我的控制器 public function ipload() { $this->load->helper('url'); $this->load->model('m_company'); $config['upload_path'] = './upl

如何使用上载库在codeigniter中上载php或html文件?我有一个控制器,它在上传jpg、gif、png文件时可以正常工作,但上传带有php、html或sql扩展名的文件时却不能正常工作

这是我的控制器

public function ipload()
{
 $this->load->helper('url');
 $this->load->model('m_company');

 $config['upload_path']          = './uploads/';
 $config['allowed_types']        = 'php|html|txt';
 $config['max_size']             = 2048;
 $config['max_width']             = 0;
 $config['max_height']             = 0;

 $this->load->library('upload', $config);

 if (!$this->upload->do_upload('userfile'))
 {
   $data = array('error' => $this->upload->display_errors());
 }
 else
 {
   $this->upload->do_upload('userfile');
   $data = array('upload_data' => $this->upload->data());
   $filen = $this->upload->data('file_name');
   $this->m_company->set_doc($filen);
 }
echo json_encode($data);
 }

当允许的文件是jpg gif png时,一切正常

首先设置controler,您可以使用access使用$config['allowed_types']='*'上传文件所有类

class c_cutipegawai extends CI_Controller{
function __construct(){
    parent::__construct();
}
function do_upload(){
    $config['upload_path']      ='./upload/SuratCuti/';
    $config['allowed_types']    ='*';
    $config['max_size']         =1024*8;
    $config['max_widht']        =1024*2;
    $config['max_height']       =768;

    $this->load->library('upload', $config);

    if(! $this->upload->do_upload('userfile')){
        $error = array('error' => $this->upload->display_errors());

    }
    else{
        $data=array('upload_data' => $this->upload->data());

    }
}
}
在控制器中设置之后,现在我们开始查看插入按钮上载文件


上传表单



首先设置Controller,您可以使用access使用$config['allowed_types']='*'上传文件所有类

class c_cutipegawai extends CI_Controller{
function __construct(){
    parent::__construct();
}
function do_upload(){
    $config['upload_path']      ='./upload/SuratCuti/';
    $config['allowed_types']    ='*';
    $config['max_size']         =1024*8;
    $config['max_widht']        =1024*2;
    $config['max_height']       =768;

    $this->load->library('upload', $config);

    if(! $this->upload->do_upload('userfile')){
        $error = array('error' => $this->upload->display_errors());

    }
    else{
        $data=array('upload_data' => $this->upload->data());

    }
}
}
在控制器中设置之后,现在我们开始查看插入按钮上载文件


上传表单



您是否尝试将允许的\u类型设置为数组?它是管道字符串的替代品,不应该有什么区别,但是上传库可能会有问题。另外,它适用于哪个版本的CodeIgniter?我现在尝试设置为array,它只适用于jpg,不适用于php、html、txt…文件。CI_版本为3.0.6。我没有提到上传不抛出错误消息或上传数据。您是否尝试将允许的上传类型设置为数组?它是管道字符串的替代品,不应该有什么区别,但是上传库可能会有问题。另外,它适用于哪个版本的CodeIgniter?我现在尝试设置为array,它只适用于jpg,不适用于php、html、txt…文件。CI_版本为3.0.6。我没有提到不要上传错误信息,也不要上传数据