如果你的文件路径是本地路径(如/var/www/uploads/myfile.txt
),你需要做一个新的PHP页面,允许用户下载文件。因此,有两个步骤:
- 写的下载网址在当前的环
- 下载创建一个新的页面
你的循环修改:
$reponse = $bdd->query("SELECT name, filename, filepath FROM documents");
while ($donnees = $reponse->fetch())
{
$files=$donnees['filename'];
// ... stuff here ...
if (preg_match($word,$line)) {
echo "<center>Word ".$word." found in the file <a href=\"download.php?file=".$filepath."\">".$files."</a></center>";
}
在的download.php :
<?php
$file=$_GET['file'];
if (($file != "") && (file_exists("./" . basename($file)))) // add some checks to avoid the download of critical files...
{
$size = filesize("./" . basename($file));
header("Content-Type: application/force-download; name=\"" . basename($file) . "\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\"");
readfile("./" . basename($file));
exit();
}
?>
我知道法国人p人们对他们的语言感到非常自豪,但如果您要求帮助,请拜托,真的请...使用英语,特别是在代码中。 –
我不以我的语言为荣:P我编辑了我的代码,对于这个错误感到抱歉。 – user3239930