下载功能如何工作

时间:2011-07-04 07:17:40

标签: php

我有一个网页,我有链接到照片和有关这个存储在MySQL中的信息。现在,如果我想为图像/音频添加下载按钮,我该如何使用PHP?

1 个答案:

答案 0 :(得分:3)

假设每个文件在数据库中都有一个ID,只需将下载按钮链接到php页面,其设置如下:

<?php 

//$file = fetch file data from db based off of $_GET['id']

header("Content-Type: application/force-download"); 
header('Content-Description: File Transfer'); 

readfile($file);