php CodeIgniter中的文件上载控制器。完整的教程:https://www.cloudways.com/blog/codeigniter-upload-file-image/

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php CodeIgniter中的文件上载控制器。完整的教程:https://www.cloudways.com/blog/codeigniter-upload-file-image/相关的知识,希望对你有一定的参考价值。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function custom_view(){
$this->load->view('custom_view', array('error' => ' ' ));
}
public function do_upload(){
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
else
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('custom_view', $error);
}
}
}
?>

以上是关于php CodeIgniter中的文件上载控制器。完整的教程:https://www.cloudways.com/blog/codeigniter-upload-file-image/的主要内容,如果未能解决你的问题,请参考以下文章