Hey guys I'm having problem at my upload image function in codeigniter.. I created a new controller for my upload function because I keep on getting error when I'm putting the upload function in my main controller.. so here is the upload.php the new controller that I made
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$this->load->view('account', array('error' => ' ' ));
}
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error'=>$this->upload->display_errors());
$this->load->view('account', $error);
}
else
{
$data=array('upload_data'=>$this->upload->data());
$data['img'] = base_url().'/uploads/';
$this->load->view('success', $data);
}
}
}
?>
Here is the account.php where the user can upload their images
<html>
<body>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" />
<br /><br />
<input type="submit" value="upload" />
</body>
</html>
and I also declared the new controller in my routes
$default_controller = "admin";
$route['verifylogin'] = 'verifylogin';
$route['home'] = 'home';
$route['upload'] = 'upload';
$controller_exceptions = array('somethingpink','forums');
$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = '';
and the problem is everytime I'm uploading an image I keep on getting "404 page not found" error..
it cant find this url http:// localhost/picturecity/index.php/upload/do_upload .. picturecity is the name of my project.. that url is automatically generated by this form_open_multipart('upload/do_upload');?> .. I don't know what's the problem.. is it the routing or failed controller.. please help me.. I need to pass my project tomorrow..
MY HTACCESS
RewriteEngine On
RewriteBase /picturecity
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Please try this. And Make sure your upload folder has 777 permission.
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = 'TRUE';
$this->load->library('upload');
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$error = array('error'=>$this->upload->display_errors());
$this->load->view('account', $error);
}
else
{
$data=array('upload_data'=>$this->upload->data());
$data['img'] = base_url().'/uploads/';
$this->load->view('success', $data);
}
}