来自 PHP 文档标题的示例
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>
downloadimage.php?name=image.jpg
<?php
// pseudo code
$md5_filename = get_md5_filename_from_database($_GET['name']);
// sending
header('Content-type: image/jpeg');
header('Content-Disposition: attachment; filename="'.$_GET['name'].'"');
readfile($md5_filename);
?>
现在您可以通过以下方式下载
www.yourdomain.com/some-path/downloadimage.php?name=image.jpg
或RewriteRule
在 Apache 配置中使用(如 Musa 所说)来获取
www.yourdomain.com/some-path/image.jpg