I have a page that will allow users to upload their picture that will act as their profile picture. I have this code:
<form method = "post" action = "" enctype="multipart/form-data">
<input type = "hidden" name = "size" value = "1000000">
<input type = "file" name = "image">
<input type = "submit" name = "upload" value = "Upload Image">
</form>
My php:
if(isset($_POST['upload'])) {
$target = "profileimgs/".$key.basename($_FILES['image']['name']);
$image = $key.basename($_FILES['image']['name']);
$sql = "UPDATE users SET img = '$image' WHERE idnumber = $idnumber";
mysqli_query($con,$sql);
if(move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
header("Location:home.php");
} else {
header("Location:error_uploading.php");
}
}
By choosing the picture, the only preview that will be shown is the picture's filename. I want to add a "preview" of their chosen image right after they chose the image. Just like when you upload a profile picture on facebook - you choose a picture from your computer, then when you click select picture
it automatically upload your picture to the page and gives you a preview to that picture wihout having to click so many buttons.
Is there something I can do to achieve something this?