html下载文件代码-PHP示例代码实现当前页面点击下载文件

PHP示例代码实现当前页面点击下载文件

更新时间:2016年11月16日10:48:22 提交:jingxian

下面小编给大家带来一段PHP实现当前页面文件点击下载的示例代码。 小编觉得还不错html下载文件代码,所以现在就分享给大家html下载文件代码,给大家一个参考。下面就跟着小编一起来看看吧。

php 控制器中的代码

public function downFile($path = ''){
    if(!$path) header("Location: /");
    download($path);
  }

下载文件下载功能代码

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'); //打开文件 
    //输入文件标签 
    header("Content-type: application/octet-stream"); 
    header("Accept-Ranges: bytes"); 
    header("Accept-Length: ".filesize($file_url)); 
    header("Content-Disposition: attachment; filename=".$file_name); 
    //输出文件内容 
    echo fread($file_type,filesize($file_url)); 
    fclose($file_type);
} 

html5下载文件的代码_代码下载文件_html下载文件代码

html代码


$(function(){
      $('.downLoad').click(function(){
        var path = $(this).attr('path');
        $('#iframe').attr('src',"php文件路径?path="+path);
      })
    })

只需将代码放入其中并在您的程序中执行即可。

上面PHP实现点击下载当前页面文件的示例代码就是编辑器分享的全部内容。 希望能给大家一个参考,也希望大家多多支持Script Home。