您好,登錄后才能下訂單哦!
這篇文章主要介紹如何使用php+ajax+h5實(shí)現(xiàn)圖片上傳功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
具體內(nèi)容如下
html頁面代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript" src="__PUBLIC__/home/js/jquery-1.11.0.js"></script> </head> <body> <form class="form-horizontal" role="form" id="myForm" action="/index/fileupsend" method="post" enctype="multipart/form-data"> 選擇文件:<input type="file" id="file1" /><br /> <input type="button" id="upload" value="上傳" /> <span id="imgWait"></span> </form> <script> $(function () { $("#upload").click(function () { $("#imgWait").html("上傳中"); var formData = new FormData(); formData.append("myfile", document.getElementById("file1").files[0]); $.ajax({ url: "/Home/index/fileupsend", type: "POST", data: formData, /** *必須false才會(huì)自動(dòng)加上正確的Content-Type */ contentType: false, /** * 必須false才會(huì)避開jQuery對(duì) formdata 的默認(rèn)處理 * XMLHttpRequest會(huì)對(duì) formdata 進(jìn)行正確的處理 */ processData: false, success: function (data) { if(data){ alert("上傳成功!"); } $("#imgWait").html("上傳成功"); }, error: function () { alert("上傳失?。?quot;); $("#imgWait").hide(); } }); }); }); </script> </body> </html>
php代碼
public function fileupsend(){ $type_pic = $this->file_upload('1',array('jpg', 'gif', 'png', 'jpeg'),'filetest','myfile'); echo $type_pic['img_path']; }
以上是“如何使用php+ajax+h5實(shí)現(xiàn)圖片上傳功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。