表格不在codeigniter 2.0中上传文件

问题描述 投票:2回答:2

我尝试了所有可能的方法但没有成功。只是尝试使用代码点火器上传文件,但没有处理我得到的错误

<pre>Array
(
 [error] => <p>You did not select a file to upload.</p>
)

我已经尝试在我的本地主机上的正常核心php工作正常但不使用代码点火器。它根本就没有选择文件。如果我查询var_dump($_FILES['fileToUpload']);,结果将是array(0)

表格代码

<form id="contact_form" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>Main/do_upload">
 <input type="file" class="form-control" name="fileToUpload" id="fileToUpload">
</form>

控制器代码

$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());
    echo "<pre>";
    var_dump($data);
    // $this->load->view('upload_success',$data);
}else{
    $error = array('error' => $this->upload->display_errors()); 
    echo "<pre>";
    print_r($error);
}

配置

$autoload['libraries'] = array("session", "email", "database");
$autoload['helper'] = array("url", "file", "form");

有什么我不知道的吗?请指导我被困在这里。

php codeigniter-2
2个回答
1
投票

你错过了do_upload()中的输入文件名:

使用 :

if(!$this->upload->do_upload('image_file'))
{
   //$this->upload->display_errors()
}
else
{
   //$this->upload->data()
}

代替:

if($this->upload->do_upload())

0
投票

你错过了qazxsw poi中的参数请检查下面的代码。

$this->upload->do_upload

public function do_upload(){ $config = array( 'upload_path' => "assets/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); $this->upload->initialize($config); if($this->upload->do_upload('fileToUpload')) { $data = array('upload_data' => $this->upload->data()); echo "<pre>"; var_dump($data); // $this->load->view('upload_success',$data); }else{ $error = array('error' => $this->upload->display_errors()); echo "<pre>"; print_r($error); } } 中传递您的文件上传名称

© www.soinside.com 2019 - 2024. All rights reserved.