保存文件onclick [英] save file onclick

查看:125
本文介绍了保存文件onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够点击下载csv文件,而不是在浏览器中打开。

我把这段代码加进去

 < a href =file.csv>下载档案< / a> 

但点击后会在浏览器中打开v文件。在本地主机中,当我点击链接时,它正在下载,但当它在服务器上时,它在浏览器中打开。

设置标题,以便通知网络浏览器打开文件保存对话框。



download.php




 <?php 
header(Content-Type:application / octet-stream);
header(Content-Disposition:attachment; filename = sample.csv);
readfile('file.csv');
?>

showlinks.php






 < a href =download.php>下载档案< / a> 


I want to be able to download the csv file on click and not open in the browser

I put this code

<a href="file.csv">download file</a>

but on click it opens thev file in the browser. In localhost, when I click the link it is being downloaded but when on the server it's opening in the browser

解决方案

You have to set headers in order to inform web-browser for opening file-save dialog.

download.php


  <?php
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=sample.csv");
    readfile('file.csv');
   ?>

showlinks.php


<a href="download.php">Download file</a>

这篇关于保存文件onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆