1、直接添加文件鏈接
2、傳遞參數查找並跳轉到下載鏈接
傳遞參數:
<button>
<a href = "http://localhost?f='down'">
下載文件
</button>查找文件並挑戰到下載鏈接:
<?php
$down = $_GET['f']; //獲取文件參數
$filename = $down.'.zip'; //獲取文件名稱
$dir ="down/"; //相對於網站根目錄的下載目錄路徑
$down_host = $_SERVER['HTTP_HOST'].'/'; //當前域名
//判斷如果文件存在,則跳轉到下載路徑
if(file_exists(__DIR__.'/'.$dir.$filename)){
header('location:http://'.$down_host.$dir.$filename);
}else{
header('HTTP/1.1 404 Not Found');
}