1<?PHP2 //1, through the Super global variable to get files[upload image name]3$file = $_files["FILES"]4 //2, to get the format of the picture by STRRCHR5$ext = STRRCHR ($file [' name '], '. ');6 //3, randomly get file name by Uniqid function to avoid duplicate name overwrite7$filename =uniqid (). $exe;8 //4, you can get the name of the picture to exist in the session, in order to avoid later use, this step can write not write;9 session_start ();Ten$_session[' url '] =$str; 19:36:16 One //5, through the Move_uploaded_file function to upload the image of the picture exists in a folder A$bool = Move_uploaded_file ($file [' tmp_name '], '. /.. /static/uploads/'. $filename); - //6. Return the processed picture path to the front end - if($bool) { theecho ". /static/uploads/". $fileName; -}Else { -echo "Upload failed"; - }; +?> - +<! DOCTYPE html> A at - -<meta charset= "UTF-8" > -<meta name= "viewport" content= "Width=device-width, initial-scale=1.0" > -<meta http-equiv= "x-ua-compatible" content= "Ie=edge" > -<title>Document</title> in<script src= ". /static/assets/vendors/jquery/jquery.min.js "></script> -<script> to$(function () { +$ ("#uploadImg"). On ("Change",function () { - //Console.log (this.files); the varFile = This. files[0]; * vardata =NewFormData (); $Data.append (' file ', file);Panax Notoginseng //console.log (data); - $.ajax ({ theType: "POST", +URL: "./api/_addposts.php", A Data:data, theDataType: "JSON", +Successfunction(res) { - Console.log (RES) $ } $ }); - }); - }) the</script> -Wuyi the<body> -<input type= "File" Name= "id=" uploadimg "> Wu</body> - About Send Ajax request to implement upload picture displayed on Web page