久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

php+iframe 實(shí)現(xiàn)上傳文件功能示例

瀏覽:117日期:2022-09-11 11:07:26

本文實(shí)例講述了php+iframe 實(shí)現(xiàn)上傳文件功能。分享給大家供大家參考,具體如下:

我們通過動(dòng)態(tài)的創(chuàng)建iframe,修改form的target,來實(shí)現(xiàn)無跳轉(zhuǎn)的文件上傳。

具體的實(shí)現(xiàn)步驟

1.捕捉表單提交事件2.創(chuàng)建一個(gè)iframe3.修改表單的target,指向iframe4.刪除iframe

file.html代碼如下:

<!DOCTYPE HTML><html lang='zh-CN'><head> <meta charset='UTF-8'> <title></title></head><body> <form action='upfile.php' method='post' enctype='multipart/form-data'> <input type='file' name='file' /> <input type='submit' name='submit' value='上傳' /> </form> <div id='result'></div></body><script type='text/javascript' src='http://www.baoyu77737.com/bcjs/jquery.js'></script><script type='text/javascript'>$('#upfileForm').bind('submit', function() { var ifrName = ’upfile’ + Math.random(); var ifr = $('<iframe name=’' + ifrName + '’ width=’0’ height=’0’ frameborder=’0’></iframe>'); $('body').append(ifr); $(this).attr('target', ifrName);});</script></html>

upfile.php代碼如下:

<?php$uploadDir = ’./upload/’;if(!file_exists($uploadDir)) { @mkdir($uploadDir, 0777, true);}$uploadFile = $uploadDir . basename($_FILES[’file’][’name’]);if(move_uploaded_file($_FILES[’file’][’tmp_name’], $uploadFile)) { echo '<script>parent.document.getElementById(’result’).innerHTML=’OK’;</script>';} else { echo '<script>parent.document.getElementById(’result’).innerHTML=’NO’;</script>';}

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php文件操作總結(jié)》、《PHP目錄操作技巧匯總》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設(shè)計(jì)算法總結(jié)》及《PHP網(wǎng)絡(luò)編程技巧總結(jié)》

希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。

標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 绥滨县| 中江县| 贞丰县| 永德县| 长春市| 民乐县| 准格尔旗| 宜君县| 时尚| 交口县| 惠东县| 青岛市| 濉溪县| 崇礼县| 博客| 英德市| 陆丰市| 汪清县| 拉萨市| 四会市| 屯留县| 共和县| 驻马店市| 疏勒县| 临朐县| 白水县| 成安县| 金门县| 北海市| 邯郸市| 五寨县| 柳州市| 中卫市| 冀州市| 繁昌县| 金坛市| 福鼎市| 奎屯市| 横山县| 万源市| 石首市|