首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在codeigniter中上传php或html文件?

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

Stack Overflow用户
提问于 2016-08-25 09:51:59
回答 1查看 899关注 0票数 1

如何使用上传库在codeigniter中上传php或html文件?我有控制器,当上传jpg,gif,png文件时工作正常,但它不会上传文件与php或html或sql扩展名。

这是我的控制器

代码语言:javascript
复制
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时,一切正常。

EN

回答 1

Stack Overflow用户

发布于 2018-07-22 01:39:25

首先你设置控件,你可以使用access上传所有类的文件

$config‘types_types’='*';

代码语言:javascript
复制
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());

    }
}
}

在控制器中设置后,现在我们可以通过craete视图来插入上传文件的按钮

代码语言:javascript
复制
<html>
<head>
<title>Upload Form</title>
</head>
<body>


<?php echo form_open_multipart('C_CutiPegawai/do_upload');?>

  <input type="file" name="userfile" size="20" />

  <br /><br />

  <input type="submit" value="upload" />

</form>

</body>	
</html>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39135519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档