Image Edit Code in Core PHP
<?php
include_once 'dbconnect.php';
$id=$_GET['/'];
$sql="select * from tbl_user where id='{$id}'";
$result_set=mysqli_query($con,$sql);
$count=mysqli_affected_rows($con);
if($count>0){
$data=mysqli_fetch_assoc($result_set);
$id=$data['id'];
$name=$data['name'];
$file=$data['file'];
}else{
echo "No Record Found";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/
css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYo
tlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/
3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHi
fhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"></script>
<title>Image</title>
</head>
<body>
<div class="container"> <br>
<h1 class="text-white bg-dark text-center">
Update Profile
</h1>
<div class="col-lg-8 m-auto d-block" style="background:aqua;">
<form action="editcode.php?/=<?php echo basename($_SERVER['PHP_SELF'])?>"
method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="user">Username</label>
<input type="hidden" name="id" class="form-control" value="<?php
echo $id; ?>">
<input type="text" name="username" id="user" class="form-control"
value="<?php echo $name; ?>">
</div>
<div class="form-group">
<label for="file">Profile Pic:</label>
<input type="file" name="file" id="file" class="form-control">
</div>
<input type="submit" name="submit" value="Submit" class="btn btn-success">
</form>
</div>
</div>
</body>
</html>
<?php
include_once 'dbconnect.php';
if($_SERVER['REQUEST_METHOD']='POST'){
if(isset($_POST['submit']) or !empty($_POST['submit'])){
$id = $_POST['id'];
$username=isset($_POST['username'])?$_POST['username']:NULL;
if(is_null($username) or empty($username)){
header("location:{$_REQUEST['/']}?action=username&msg=blank-username&/
=$id");
exit;
}
$file=$_FILES['file'];
$file_name = $file['name'];
$file_type = $file['type'];
$file_tmp_name = $file['tmp_name'];
$file_error = $file['error'];
$file_size = $file['size'];
$fs = $file_size/1024;
$arr = ['jpg','png','jpeg'];
$fi= explode(".",$file_name);
$last = end($fi);
if(in_array($last,$arr))
{
if($fs<=500)
{
if($file_error==0)
{
// $file_path = __DIR__."/vv/";
// $upload_files = $file_path.$file_name;
// if( move_uploaded_file($file_tmp_name,$upload_files))
// {
$file_path = __DIR__."/upload/vv/";
$upload_files = $file_path.$file_name;
// echo $upload_files;
// exit;
if(move_uploaded_file($file_tmp_name,$upload_files))
{
$insertquery="update tbl_user set name='{$username}' ,
file='{$file_name}' where id='{$id}'";
$ifile=mysqli_query($con,$insertquery) or die($con);
if($ifile){
?>
<script>
window.alert("file updated successfully");
window.location.href="show.php";
</script>
<?php
}else{
header("location:edit.php?/={$id}");
}
}else{
echo "No File Movienig";
}
}else{
echo "File Uploading Error";
}
}else{
echo "File Size Should be bellow 500kb";
}
}else{
echo "<br> InValid image";
}
}
}else{
header("location:edit.php?msg=Invalid-Request");
}
?>
0 Comments