点击链接时触发php文件,php点击链接直接下载文件写法

down.php

<?php

$file = "avater.jpg"; //计算机上的一个文件

$fileName = basename($file); //获取文件名

header("Content-Type:application/octet-stream"); //告诉浏览器文档类型(mime类型); octet-stream指的是二进制文件类型;下载任何类型的文件都可以这么指定

header("Content-Disposition:attachment;filename=".$fileName); //告诉浏览器以附件方式对待文件(即下载文件);并设置下载后的文件名

header("Accept-ranges:bytes"); //告诉浏览器文件大小的单位

header("Accept-Length:".filesize($file)); //告诉浏览器文件的大小

$h = fopen($file, 'r'); //打开文件

echo fread($h, filesize($file));

index.html

<!DOCTYPE html>

<html lang="zh-CN">

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->

<title>Bootstrap 101 Template</title>

<!-- Bootstrap -->

<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"

crossorigin="anonymous">

<script>

</script>

<style>

.fade-enter-active,

.fade-leave-active {

transition: opacity .5s

}

.fade-enter,

.fade-leave-to

/* .fade-leave-active in below version 2.1.8 */

{

opacity: 0

}

</style>

</head>

<body style="text-align:center">

<h1 class="text-center">测试用</h1>

<div id="app">

<div v-show="1" class="panel panel-default" v-for="permission in permissions">

<div class="panel-heading">

<h3 class="panel-title" v-bind:data-id="5" v-on:click="changeShow">面板标题</h3>

</div>

<div class="panel-body" v-show="0">

<div>

hehe

</div>

</div>

</div>

姓名:<input id='start_time' type="text"><br/> 年龄:

<input id='end_time' type="text"> 下载文件:

<button @click="download" type="button">ajax下载文件</button>

<a href="download.php">直接链接下载文件</a></div>

<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>

<script src="/laydate/laydate.js"></script>

<script src="vue.js"></script>

<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"

crossorigin="anonymous"></script>

</body>

</html>

<script>

laydate.render({

elem:'#start_time' //指定元素

});

laydate.render({

elem:'#end_time' //指定元素

});

var app = new Vue({

el:'#app',

data:{

permissions:[{'name':'zxj'},{'name':'shepeng'},{'name':'zhangqiang'},{'name':'jiachang'}],

show:[],

},

methods:{

changeShow:function (event) {

// console.log(event.target.dataset.id);

// event.target.dataset.id = !event.target.dataset.id;

console.log(event.target.appendChild(para));

},

download:function (e) {

$.ajax({

type:'post',

url:'download.php',

data:{

name:e.target.innerHTML

},

dataType:'json',

success:function (res) {

console.log(res);

alert(res.name);

}

});

}

}

});

</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值