File size: 2.13Kb
<?php
session_start();
include "../../lib/functions_class.php";
function updateimg(){
if($_FILES['file']['size'] != 0) {
$img = rand().basename($_FILES["file"]["name"]);
}else{
$img = basename($_POST["featureimg"]);
}
return $img;
}
function imagecheck($target_dir,$target_file){
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if($_FILES['file']['size'] != 0) {
$check = getimagesize($_FILES["file"]["tmp_name"]);
if($check === false) {
echo "File is not an image.";
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
}
}
//File Upload
function fileupload($target_file){
//if($_FILES['file']['size'] != 0) {
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
// }
}
//Image
$target_dir = "../../uploads/profile/";
$imgname = updateimg();
$target_file = $target_dir . $imgname;
$checkimg = imagecheck($target_dir,$target_file);
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$addressone=$_POST['addressone'];
$addresstwo=$_POST['addresstwo'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$country=$_POST['country'];
$state=$_POST['state'];
$city=$_POST['city'];
$postal=$_POST['postal'];
$dob = $_POST['dob'];
$marital_stat = $_POST['marital_stat'];
$id=$_POST['id'];
$action=$_POST['action'];
if($action == 'updateprofile'){
if($fname == ''){
echo "Please enter first name";
}
else if($lname == ''){
echo "Please enter last name";
}
else if($country == ''){
echo "Please select country";
}
else if($state == ''){
echo "Please select state";
}
else if($email == ''){
echo "Please enter email";
}
else{
$re = $DB->update_profile($fname,$lname,$addressone,$addresstwo,$mobile,$email,$country,$state,$city,$postal,$dob,$marital_stat,$id,$imgname);
fileupload($target_file);
echo 2;
}
}
if($action == 'deleteimg'){
$img = $target_dir.$_POST['img'];
unlink($img);
}
?>