小编Rep*_*ces的帖子

按钮下载.txt文件(PHP和HTML)

好的,我希望我的用户能够下载.txt带有用户名的文件.

我到处检查,到目前为止,我无法找到我想要的,或者如果它甚至有可能.

为了举例说明我正在尝试做的事情,这是我的代码:

<button type="button">Download All Your Keys On A .txt
<?php
$file = 'logs/$session->username.txt';

if(!file_exists($file)) die("I'm sorry, the file doesn't seem to exist.");

$type = filetype($file); // Get a date and timestamp $today = date("F j, Y, g:i a"); $time = time(); // Send file headers header("Content-type: $type"); header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary"); 
header('Pragma: no-cache'); 
header('Expires: 0'); // Send the file contents.
set_time_limit(0); 
readfile($file);
?>
</button>
Run Code Online (Sandbox Code Playgroud)

我正在尝试这样做,以便当您单击按钮时,它会强制下载配置为的.txt文件:

$file = 'logs/$session->username.txt';
Run Code Online (Sandbox Code Playgroud)

对不起,如果这令人困惑和混乱,但没有其他方式让我提出这个.

提前致谢!

html php

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

html ×1

php ×1