codeigniter 3-你没有选择一个文件上传 [英] codeigniter 3- You did not select a file to upload
问题描述
Post_plot.php(这是我的查看表单)
< form action =http:// localhost:8080 / ci / admin / plot / do_uploadenctype =multipart / form-datamethod =post>
< input type =textname =property_titlevalue =/>
< input type =filename =imgid =plot-imgvalue =/>
< input type =submitname =submitvalue =Submit/>
< / form>
我有一个长形式的图片上传选项。
我正在使用do_upload函数来上传文件
我得到以下错误
Array([name] => a.jpg [type] => image / jpeg [tmp_name] => C:\xampp\tmp\phpBD75.tmp [error] = > 0 [size] => 132277)Array([error] =>
您没有选择要上传的文件。
)
$ c $ P>
$ p $ < ?php
defined('BASEPATH')或者exit('不允许直接访问脚本');
class Plot extends CI_Controller {
public function __construct()
{
parent :: __ construct();
$ this-> load->库('Admin_layout');
$ this-> load->模型('admin / plot_model');
$ this-> config-> load('plot_rules');
$ this-> output-> enable_profiler(TRUE);
$ b $ 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->库('upload',$ config);
$ b $ if(!$ this-> upload-> do_upload($ img))
{
$ error = array('error'=> $ this-> ; upload->的display_errors());
print_r($ error);
$ data = array('upload_data'=> $ this-> upload-> data());
// $ this-> load-> view('upload_success',$ data);
print_r($ data);
}
} // do_upload
} // class
我应该在do_upload函数中传递任何参数吗?
/ b>
$ img =img//输入名称=img
$ this->上传 - > do_upload($ img)
如果不使用form action = 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
您可能需要在你的ro上设置一些路线
$ b $ <?php defined(' BASEPATH')或退出('不允许直接访问脚本');
class Plot extends CI_Controller {
public function __construct()
{$ b $ parent :: __ construct();
$ this-> load->库('Admin_layout');
$ this-> load->模型('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->库('upload',$ config);
$ img =img;
$ b $ if(!$ this-> upload-> do_upload($ img))
{
$ error = array('error'=> $ this-> ; upload->的display_errors());
$ this-> load-> view('upload_form',$ error);
print_r($ error);
$ 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);
}
}
}
Post_plot.php (This is my view form)
<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>
I have a long form with an image upload option.
I am using do_upload function to upload file
I am getting following error
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 Controller
<?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
Should i pass any parameters in do_upload function?
In this part try to put the
$img = "img" // input name="img"
$this->upload->do_upload($img)
If not try / test with form action="http://localhost:8080/ci/admin/plot/do_upload"
Codeigniter 2 User Guide http://www.codeigniter.com/userguide2/libraries/file_uploading.html
Codeigniter 3 User Guide http://www.codeigniter.com/user_guide/libraries/file_uploading.html?highlight=file%20upload
You may need to set some routes in your route.php
Code
<?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);
}
}
}
这篇关于codeigniter 3-你没有选择一个文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!