這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)利用php怎么實(shí)現(xiàn)一個(gè)點(diǎn)擊頁(yè)面下載文件功能,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
php控制器中代碼
public function downFile($path = ''){ if(!$path) header("Location: /"); download($path); }
download文件下載函數(shù)代碼
function download($file_url,$new_name=''){ if(!isset($file_url)||trim($file_url)==''){ echo '500'; } if(!file_exists($file_url)){ //檢查文件是否存在 echo '404'; } $file_name=basename($file_url); $file_type=explode('.',$file_url); $file_type=$file_type[count($file_type)-1]; $file_name=trim($new_name=='')?$file_name:urlencode($new_name); $file_type=fopen($file_url,'r'); //打開(kāi)文件 //輸入文件標(biāo)簽 header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); header("Accept-Length: ".filesize($file_url)); header("Content-Disposition: attachment; filename=".$file_name); //輸出文件內(nèi)容 echo fread($file_type,filesize($file_url)); fclose($file_type); }
html代碼
<iframe id="iframe" src="" ></iframe> $(function(){ $('.downLoad').click(function(){ var path = $(this).attr('path'); $('#iframe').attr('src',"php文件路徑?path="+path); }) })
把上面的代碼,分別放到你的程序中執(zhí)行就可以了
上述就是小編為大家分享的利用php怎么實(shí)現(xiàn)一個(gè)點(diǎn)擊頁(yè)面下載文件功能了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享題目:利用php怎么實(shí)現(xiàn)一個(gè)點(diǎn)擊頁(yè)面下載文件功能-創(chuàng)新互聯(lián)
轉(zhuǎn)載源于:http://jinyejixie.com/article16/gpegg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、動(dòng)態(tài)網(wǎng)站、外貿(mào)建站、企業(yè)建站、網(wǎng)站設(shè)計(jì)公司、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容