HTML JS PHP

UPLOAD IMAGE WITH AJAX IN PHP

(a quick example)

<form id="upForm" onsubmit="return up();">   <input type="file" accept="image/*"                name="up" required>   <input type="submit" value="Upload"> </form>

HTML UPLOAD FORM

01

AJAX FILE UPLOAD

02

function up () {   GET SELECTED IMAGE   var data = new FormData(document.   getElementById("upForm"));

  AJAX UPLOAD   fetch("upload.php", { method:"POST",    body:data })   .then(res => res.text())   .then(txt => alert(txt))   .catch(err => console.error(err));   return false; }

SAVE UPLOADED FILE echo move_uploaded_file(   $_FILES["up"]["tmp_name"],   $_FILES["up"]["name"] ) ? "OK" : "ERROR" ;

PHP SAVE FILE UPLOAD

03