Php Codeigniter-无法在Codeigniter中上载文件.pdf
我想上传一个pdf文件,但如果文件大小超过3MB,则无法上传该文件 这是我的配置:Php Codeigniter-无法在Codeigniter中上载文件.pdf,php,codeigniter,pdf,upload,document,Php,Codeigniter,Pdf,Upload,Document,我想上传一个pdf文件,但如果文件大小超过3MB,则无法上传该文件 这是我的配置: $config = array( 'upload_path'=>'./assets/file/', 'allowed_types' => 'pdf', 'overwrite' => TRUE, 'max_size' => '0', 'file_name' => $_FILES['file_peta']['name'] ); Codeignit
$config = array(
'upload_path'=>'./assets/file/',
'allowed_types' => 'pdf',
'overwrite' => TRUE,
'max_size' => '0',
'file_name' => $_FILES['file_peta']['name']
);
Codeigniter只是链条中的一个环节。即使在上载库中,您没有限制最大文件大小,但还有两个地方需要检查: 1.-PHP的配置指令 2.-Nginx或Apache的配置指令
每一个前者都有一个max upload size指令。在您的案例中,真正的限制是三者的下限,因此您需要检查这些配置(或者让系统管理员为您执行),并设置一个适合您的限制Codeigniter只是链中的一个链接。即使在上载库中,您没有限制最大文件大小,但还有两个地方需要检查:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
1.-PHP的配置指令
2.-Nginx或Apache的配置指令
每一个前者都有一个max upload size指令。在您的案例中,真正的限制是三者的下限,因此您需要检查这些配置(或者让系统管理员为您执行),并设置一个适合您的限制
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
定期访问
定期访问 以下是您可以使用的代码片段:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class UploadFileController extends CI_Controller {
public function __construct() {
parent::__construct();
// add these lines
$this->load->library('upload');
$this->load->helper(array('form', 'url'));
}
public function index(){
$this->load->view('home', array('error' => ' ' ));
}
public function do_upload(){
$config = array(
'upload_path' => "./uploads/", // here add directory path where you want to upload and do not forget to give permission
'allowed_types' => "gif|jpg|png|jpeg|pdf", // you can add many more types
'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('home', $error);
}
}
}
?>
以下是您可以使用的代码片段:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class UploadFileController extends CI_Controller {
public function __construct() {
parent::__construct();
// add these lines
$this->load->library('upload');
$this->load->helper(array('form', 'url'));
}
public function index(){
$this->load->view('home', array('error' => ' ' ));
}
public function do_upload(){
$config = array(
'upload_path' => "./uploads/", // here add directory path where you want to upload and do not forget to give permission
'allowed_types' => "gif|jpg|png|jpeg|pdf", // you can add many more types
'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('home', $error);
}
}
}
?>
上载库配置只是问题的一部分。即使Codeigniter没有限制文件大小,PHP安装和服务器软件(无论是Apache还是Nginx)都有自己的限制。默认情况下,PHP将上传限制为2Mb,IIRC,Apache和Nginx也是如此。您还需要处理这些限制,因为有效约束是由允许的最低值3(您的代码、PHP和服务器指令)决定的。这里有一些提示:上载库配置只是问题的一部分。即使Codeigniter没有限制文件大小,PHP安装和服务器软件(无论是Apache还是Nginx)都有自己的限制。默认情况下,PHP将上传限制为2Mb,IIRC,Apache和Nginx也是如此。您还需要处理这些限制,因为有效约束由允许的最低值3(您的代码、PHP和服务器指令)决定。这里有一些提示:欢迎使用stackoverflow。虽然这可能回答了这个问题,但如果你能解释一下原因,那就更有用了。欢迎来到stackoverflow。虽然这可能回答了这个问题,但如果你能解释一下原因,那就更有用了。