codeigniter 3- You did not select a file to upload -
post_plot.php (this 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 long form image upload option.
i using do_upload function upload file
i getting following error
array ( [name] => a.jpg [type] => image/jpeg [tmp_name] => c:\xampp\tmp\phpbd75.tmp [error] => 0 [size] => 132277 ) array ( [error] => did not select file 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 pass parameters in do_upload function?
in part try put
$img = "img" // input name="img" $this->upload->do_upload($img)
if not try / test 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 set routes in 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); } } }
Comments
Post a Comment