我有一个网站,我希望能够放置一个链接,使用户能够下载php文件,我不希望它运行或让用户导航到URL,但能够下载原始文件,这可能吗?
谢谢
谢谢 Biswajit,该链接为我提供了我需要的东西(我看到了原始的"重复",但我不适合我)
<?php
// Fetch the file info.
$filePath = '/path/to/file/on/disk.jpg';
if(file_exists($filePath)) {
$fileName = basename($filePath);
$fileSize = filesize($filePath);
// Output headers.
header("Cache-Control: private");
header("Content-Type: application/stream");
header("Content-Length: ".$fileSize);
header("Content-Disposition: attachment; filename=".$fileName);
// Output file.
readfile ($filePath);
exit();
}
else {
die('The provided file path is not valid.');
}
?>