[eluser]Bl4cKWid0w[/eluser]
I am having some problems with the upload class. I am trying to finish my profile page but it's not working properly because the upload data function doesn't seem to be working(unless it's my logic that's the problem). What I am trying to do is have the script upload the file if the user opts to upload a new photo(if the photo input isn't blank). If they don't select a new file, the script just updates the user's photo as the old one. When I submit the form with a photo, it says my $file variable doesn't exist, even though I set it with the $this->upload->data()function. This is my code:
Code:
function edit(){
$this->load->model('constant');
$this->constant->header();
if((!$this->session->userdata('id') == $this->uri->segment(3)) || (!$this->session->userdata('rank') == 5)){ //Is the user trying to edit their own profile, or someone else's profile? Do they have permission?
$data['heading'] = "Oops!";
$data['message'] = "You do not have permission to edit this profile.";
$this->load->view('error_view', $data);
} else { //If they do have permission, load their current profile information in the form.
$this->load->library('form_validation');
$this->form_validation->set_rules('location','Location','min_length[5]|max_length[20]|xss_clean');
$this->form_validation->set_rules('aim','AIM','min_length[5]|max_length[25]|xss_clean');
$this->form_validation->set_rules('msn','MSN','valid_email');
$this->form_validation->set_rules('yahoo','Yahoo','valid_email');
$this->form_validation->set_rules('email','Email','valid_email');
$query = $this->db->query("SELECT * FROM members WHERE memberID = '".$this->uri->segment(3)."'");
$member = $query->row();
if($this->form_validation->run() == FALSE){
if($member->displayname == $this->session->userdata('username')){
$membername = "Your";
} else {
$membername = $member->displayname."'s";
}
$data['member'] = array(
'id' => $member->memberID,
'rank' => $member->rank,
'username' => $membername,
'location' => $member->location,
'aim' => $member->aim,
'msn' => $member->msn,
'yahoo' => $member->yahoo,
'email' => $member->email
);
$data['rankquery'] = $this->db->query("SELECT * FROM ranks ORDER BY power DESC");
$this->load->view('profile_edit', $data);
} else {
if($this->input->post('photo')){ //If the member opted to upload a new photo
$config['upload_path'] = "system/application/views/images/attachments/";
$config['allowed_types'] = 'gif|jpg|png|bmp|tiff';
$config['max_size'] = '100';
$config['max_width'] = '800';
$config['max_height'] = '600';
$config['overwrite'] = FALSE;
$this->load->library('upload',$config);
if (!$this->upload->do_upload('photo')){
$error = array('error' => $this->upload->display_errors());
$data['heading'] = "Oops!";
$data['message'] = "The system encountered a problem while uploading the requested photo. Please go back and try again.<ul>".$this->upload->display_errors('<li>','</li>')."</ul>";
$this->load->view('error_view',$data);
$file['file_name'] = $member->photo;
} else {
$this->upload->do_upload('photo');
$file = $this->upload->data();
}
} else { // If the member did not opt to upload a new photo
$file['file_name'] = $member->photo;
}
$new = array(
'location' => $this->input->post('location'),
'aim' => $this->input->post('aim'),
'msn' => $this->input->post('msn'),
'yahoo' => $this->input->post('yahoo'),
'email' => $this->input->post('email'),
'photo' => $file['file_name']
);
$this->db->where('memberID',$this->uri->segment(3));
$this->db->update('members',$new);
$data = array(
'heading' => "Thank You",
'message' => "Your profile information has been saved."
);
$this->load->view('error_view', $data);
}
}
$this->load->view('overall_footer');
}
Thanks for any help in advance.