[eluser]James_B[/eluser]
Ok guys this is really gettin on my nerves this issue - How come when I go on to my profile page which features a profile image upload function when I first access the page I first get the error:
Severity: Notice
Message: Undefined variable: error
Filename: homeprofile/upload_form.php
Line Number: 3
This error is Im supposed to see should only appear when I dont an image to upload despite pressing upload - You did not select a file to upload.
And then when I DO select a file to upload I get this error instead of the success page - The upload path does not appear to be valid. I have made sure the images folder was easily accessible
Please please take a look at my code:
View file
Upload_form:
Code:
<div id="maincontent">
<div id="primary">
<?php echo $error;?>
<?=form_open_multipart('homeprofile/upload');?>
<input type="file" name="userfile" />
<?=form_submit('submit', 'upload')?>
<?=form_close();?>
</div>
</div>
Controller:
Code:
<?php
class HomeProfile extends CI_Controller
{
function HomeProfile()
{
parent::__construct();
$this->load->model("profiles");
$this->load->model("profileimages");
$this->load->helper(array('form', 'url'));
}
function upload()
{
$config['upload_path'] = '/imges/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
//fail show upload form
if (! $this->upload->do_upload())
{
$error = array('error'=>$this->upload->display_errors());
$username = $this->session->userdata('username');
$viewData['username'] = $username;
$viewData['profileText'] = $this->profiles->getProfileText($username);
$this->load->view('shared/header');
$this->load->view('homeprofile/homeprofiletitle', $viewData);
$this->load->view('shared/nav');
$this->load->view('homeprofile/upload_form', $error);
$this->load->view('homeprofile/homeprofileview', $viewData, array('error' => ' ' ));
$this->load->view('shared/footer');
}
else
{
//successful upload so save to database
$file_data = $this->upload->data();
$data['img'] = base_url().'/images/'.$file_data['file_name'];
// you may want to delete the image from the server after saving it to db
// check to make sure $data['full_path'] is a valid path
// get upload_sucess.php from link above
$this->load->view('upload_success', $data);
$username = $this->session->userdata('username');
}
}