最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php實(shí)現(xiàn)當(dāng)前頁面點(diǎn)擊下載文件的簡單方法

 更新時間:2016年09月22日 19:19:46   投稿:jingxian  
下面小編就為大家?guī)硪黄猵hp實(shí)現(xiàn)當(dāng)前頁面點(diǎn)擊下載文件的簡單方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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'); //打開文件 
    //輸入文件標(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="" style="display: none;"></iframe>
$(function(){
      $('.downLoad').click(function(){
        var path = $(this).attr('path');
        $('#iframe').attr('src',"php文件路徑?path="+path);
      })
    })

把上面的代碼,分別放到你的程序中執(zhí)行就可以了。

以上就是小編為大家?guī)淼膒hp實(shí)現(xiàn)當(dāng)前頁面點(diǎn)擊下載文件的簡單方法的全部內(nèi)容了,希望對大家有所幫助,多多支持腳本之家~

相關(guān)文章

最新評論

上蔡县| 嵩明县| 无棣县| 华阴市| 陆丰市| 高淳县| 焦作市| 秦安县| 抚松县| 西平县| 孙吴县| 新丰县| 龙陵县| 皮山县| 吉安市| 东兴市| 吴旗县| 中西区| 西乡县| 莱州市| 莱西市| 苍山县| 郯城县| 元朗区| 剑河县| 右玉县| 台湾省| 镇江市| 曲阜市| 临安市| 广东省| 莱阳市| 兴文县| 万载县| 岑巩县| 华亭县| 崇礼县| 彝良县| 延边| 磴口县| 永兴县|