codeigniter 3-您没有选择要上传的文件
Posted
技术标签:
【中文标题】codeigniter 3-您没有选择要上传的文件【英文标题】:codeigniter 3- You did not select a file to upload 【发布时间】:2015-07-08 02:41:55 【问题描述】:Post_plot.php(这是我的视图)
<form action="http://localhost:8080/ci/admin/plot/do_upload" enctype="multipart/form-data" method="post">
<input type="text" name="property_title" value="" />
<input type="file" name="img" id="plot-img" value="" />
<input type="submit" name="submit" value="Submit" />
</form>
我有一个带有图片上传选项的长表单。
我正在使用do_upload函数上传文件
我收到以下错误
Array ( [name] => a.jpg [type] => image/jpeg [tmp_name] => C:\xampp\tmp\phpBD75.tmp [error] => 0 [size] => 132277 ) Array ( [error] =>
You did not select a file to upload.
)
Plot.php 控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Plot extends CI_Controller
public function __construct()
parent::__construct();
$this->load->library('Admin_layout');
$this->load->model('admin/plot_model');
$this->config->load('plot_rules');
$this->output->enable_profiler(TRUE);
public function do_upload()
$config['upload_path'] = '../images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($img))
$error = array('error' => $this->upload->display_errors());
print_r($error);
else
$data = array('upload_data' => $this->upload->data());
//$this->load->view('upload_success', $data);
print_r($data);
//do_upload
//class
我应该在 do_upload 函数中传递任何参数吗?
【问题讨论】:
【参考方案1】:在这部分尝试把
$img = "img" // input name="img"
$this->upload->do_upload($img)
如果不尝试/测试表格action="http://localhost:8080/ci/admin/plot/do_upload"
Codeigniter 2 用户指南 http://www.codeigniter.com/userguide2/libraries/file_uploading.html
Codeigniter 3 用户指南 http://www.codeigniter.com/user_guide/libraries/file_uploading.html?highlight=file%20upload
你可能需要在你的 route.php 中设置一些路由
代码
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Plot extends CI_Controller
public function __construct()
parent::__construct();
$this->load->library('Admin_layout');
$this->load->model('admin/plot_model');
$this->config->load('plot_rules');
$this->output->enable_profiler(TRUE);
public function index()
$this->load->view('upload_form', array('error' => ' ' ));
public function do_upload()
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$img = "img";
if ( ! $this->upload->do_upload($img))
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
print_r($error);
else
$data = array('upload_data' => $this->upload->data());
$field_data = $this->upload->data();
echo $field_data['file_name']; // etc
$this->load->view('upload_success', $data);
print_r($data);
【讨论】:
是的,现在很好,但它说上传路径似乎无效。我的图像文件夹位于项目根目录 --application --images --system 而不是$config['upload_path] = '../images/';
有很多..
尝试$config['upload_path] = './images/';
因为用户指南的图像目录应该在主目录中
我还添加了字段数据,以防您需要向数据库添加名称以上是关于codeigniter 3-您没有选择要上传的文件的主要内容,如果未能解决你的问题,请参考以下文章