In this code we learn about How to upload a image or any type of file in our server using php. this is a code of codigniter 3. but doing some chages we can user this code in our core php. and any other php framework also
public function update_profile(){
if(!($this->session->has_userdata('user_email'))){
redirect('student/login');
}else{
$email= $this->session->userdata('user_email');
if($_FILES['profile']['name'] != ''){
$img_size = $_FILES['profile']['size'];
if($img_size < 5242880){
$filename = $_FILES['profile']['name'];
$ext = pathinfo($filename,PATHINFO_EXTENSION);
$valid_ext = array("jpg","jpeg","png");
if(in_array($ext ,$valid_ext)){
$new_name = rand().".".$ext;
$path = "assets/student/student_image/".$new_name;
$move = move_uploaded_file($_FILES['profile']['tmp_name'],$path);
if($move){
$data['image'] = $new_name;
$this->db->update('councellor_task', $data, array('email'=>$email));
$this->session->set_flashdata('img_upload','Image Susseccfully uploaded.');
}else{
$this->session->set_flashdata('img_error','Something wrong Try again.');
}
}else{
$this->session->set_flashdata('img_error','Upload Only jpg,jpeg and png image.');
}
}else{
$this->session->set_flashdata('img_error','Image less then 5mb only.');
}
}else{
$this->session->set_flashdata('img_error','Image not Selected.');
}
redirect(base_url().'student/account' , 'refresh');
}
}
Comments
Post a Comment