There is such a function for uploading photos to the database using php, how to rewrite all this in JS so that everything happens without reloading the page?

<form method="post" style = "width:50%; margin-left:200px" enctype="multipart/form-data"> <div class="v-title">Upload your FRONT image photo</div> <div class="profile__drag profile__drag--v"> <img id="photo" src="img/icons/v-plus.png" width="100" height="100" name="image"> <div class="profile__drag-info"> <input type="file" onchange="document.getElementById('photo').src = window.URL.createObjectURL(this.files[0])" name="file" /> <input type="submit" name="uploadf" value="Upload" / onclick=fff("Upload!")> </div> </div> </form> <?php if(isset($_POST['uploadf'])) { if(empty($_FILES['file']['size'])) die('Вы не выбрали файл'); if($_FILES['file']['size'] > (5 * 1024 * 1024)) die('image size <5mb'); $imageinfo = getimagesize($_FILES['file']['tmp_name']); $arr = array('image/jpeg','image/gif','image/png'); if(!in_array($imageinfo['mime'],$arr)) echo ('image format'); else { $upload_dir = './img/front/'; $name = $upload_dir.date('YmdHis').basename($_FILES['file']['name']); $mov = move_uploaded_file($_FILES['file']['tmp_name'],$name); if($mov) { $name = stripslashes(strip_tags(trim($name))); $mysqli->query("UPDATE Verification SET IMGfront='$name' WHERE id='".$sesion_id."'"); } } } ?> 

1 answer 1

To do this with PHP alone, use AJAX.

Here is a good example, https://wp-kama.ru/id_9026/jquery-ajax-zagruzka-fajlov-na-server.html