Resim Ekleme ve Güncelleme

 

Şifre               




 
<form action="" method="post">
<label>Kullanıcı Adı</label>
<input name="user_name" type="text" /><br />

<label>Şifre</label>
<input name="user_job" type="text" /><br />

<label>Profil Resmi</label>
<img height="150" src="user_images/&lt;?php echo $userPic; ?&gt;" width="150" />
<input accept="image/*" name="user_image" type="file" />

<button name="btn_save_updates" type="submit"> Update </button>
       
</form>


if(isset($_POST['btn_save_updates']))
{
$username = $_POST['user_name'];// user name
$userjob = $_POST['user_job'];// user email

$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];

if($imgFile)
{
$upload_dir = 'user_images/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
$userpic = rand(1000,1000000).".".$imgExt;
if(in_array($imgExt, $valid_extensions))
{
if($imgSize < 5000000)
{
unlink($upload_dir.$edit_row['userPic']);
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else
{
$errMSG = "Sorry, your file is too large it should be less then 5MB";
}
}
else
{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
}
else
{
// if no image selected the old image remain as it is.
$userpic = $edit_row['userPic']; // old image from database
}



if(!isset($errMSG))
{
$stmt = $DB_con->prepare('UPDATE tbl_users SET userName=:uname,userProfession=:ujob, userPic=:upic WHERE userID=:uid');
$stmt->bindParam(':uname',$username);
$stmt->bindParam(':ujob',$userjob);
$stmt->bindParam(':upic',$userpic);
$stmt->bindParam(':uid',$id);

if($stmt->execute()){
?>
                <script>
alert('Successfully Updated ...');
window.location.href='index.php';
</script>
                <?php
}
else{
$errMSG = "Sorry Data Could Not Updated !";
}

}
}

Hiç yorum yok:

Yorum Gönder