Reputation: 1845
I use the exact code from the CI
https://www.codeigniter.com/user_guide/libraries/file_uploading.html
but it always keep on giving me same error that
The upload path does not appear to be valid.
The folder is there and path is ok . Folder has write permission .
Controller code is this
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = '/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
print_r($config);
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
//echo 'path : '.$config['upload_path'];
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
//echo "submited";
}
}?>
Upvotes: 1
Views: 7374
Reputation: 516
Your problem is on following line.
$this->load->library('upload', $config);
$this->upload->initialize($config);
Instead of this just do
$this->upload->initialize($config);
and load upload library from auto load.
Upvotes: 0
Reputation: 1845
I figure it out the problem . I was creating the folder in the controller folder . The upload folder should be created at the root folder where Codeignator is installed . In my case CI was installed at this path
localhost/CI/
so i created the folder with name of upload and it works for me .
Upvotes: 1
Reputation: 4305
Just create a folder with name 'uploads'
in application folder directory. And change you upload path coding line in your controller like below.
$config['upload_path'] = './uploads/';
Upvotes: 0