I am having issues uploading an image using the codeigniter upload library, I keep getting the error,
The upload path does not appear to be valid.
The file path I am trying to upload too is as follows,
$config['upload_path'] = './media/images/site';
and when I dot the following,
die(var_dump(is_dir($config['upload_path'])));
I get the following returned,
bool(true)
The folder is also writable (777), so I am not sure where I am going wrong, below is my upload code,
$config['upload_path'] = './media/images/site';
//die(realpath($config['upload_path']));
//die(var_dump(is_dir($config['upload_path'])));
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1500';
$config['max_width'] = '390';
$config['max_height'] = '269';
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload() && $_FILES['userfile']['error'] != 4)
{
$data['error'] = $this->upload->display_errors();
$this->template->build('/admin/pages/about_us', $data);
}
else
{
$image = $this->upload->data();
if(empty($image['file_name'])) {
$image['file_name'] = $this->formbuilder->defaults['page_image'];
}
$page = array(
//'page_title' => $this->input->post('page_title'),
//'page_slug' => $this->input->post('page_slug'),
'page_content' => $this->input->post('page_content'),
'page_image' => $image['file_name'],
'date_created' => date("Y-m-d h:i:s"),
'created_by' => 1
);
if($this->pages_model->insert($this->security->xss_clean($page)))
{
redirect('/admin/dashboard');
}
}
I cannot see anything glaringly obvious that would stop the file from being uploaded, below is my folder structure of my project
/application
/system
index.php
.htaccess
/media
/images
/site
/admin
/css
/js
If anyone can shed any light on my problem that would be great.
EDIT FOR THE PETULENT DOWNVOTER
What would be causing this problem?
(There is a question, as if it wasn't obvious enough anyway)
Try to add this line before libary loading line:
// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
$this->upload->initialize($config);
Don't forget to add this line in template:
<?php echo form_open_multipart('upload/do_upload');?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With