HTML JS PHP

SIMPLE AJAX IMAGE UPLOAD WITH PHP

<form onsubmit="return up();">   <input type="file" id="upfile" required/              accept=".png,.gif,.jpg,.webp">   <input type="submit" value="GO!"/> </form>

HTML UPLOAD FORM

01

AJAX FILE UPLOAD

02

function up () {   FILE TO UPLOAD   var data = new FormData();   data.append("up", document.   getElementById("upfile").files[0]);

  AJAX UPLOAD   fetch("UP.PHP", { method:"POST",  body:data})   .then(res=>res.text())   .then((res) => { alert(res); });   return false; }

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

PHP SAVE FILE UPLOAD

03