Reputation: 305
When i upload file it say that 'The upload path does not appear to be valid.'
print_r($_FILES);
print the file info. What I am making wrong?
My directory tree is this Directory
class Upload_pdf extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
public function do_upload_pdf()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
print_r($_FILES);
?>
Upvotes: 0
Views: 200
Reputation: 2352
Here is your project directory tree
/erp-system
/application
-/config
-/controllers
-/cache
-/core
/system
index.php
Just update the $config['upload_path']
like this
If uploads folder inside the application
folder
$config['upload_path'] = APPPATH.'uploads';
If outside the application folder
$config['upload_path'] = FCPATH.'uploads';
APPPATH
is the application
folder of your project.
FCPATH
is the project folder erp-system
Upvotes: 2
Reputation: 5322
Autoload upload library in config/autoload file $autoload['libraries'] = array("upload");
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->upload->initialize($config);
if(!$this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
Upvotes: 0