如何允许用户下载服务器上保存的图片?目标是让用户单击链接并开始下载指定的图像。
Facebook 示例:
最佳答案
链接到另一个 .php 页面,而不是图像。然后在该页面上使用内容处置 header ,如下所示:
<?php
// Define the name of image after downloaded
header('Content-Disposition: attachment; filename="file.jpg"');
// Read the original image file
readfile('file.jpg');
?>
从那里,您只需在 get 命令中添加图像的文件名,例如
`download.php?filename=file`
然后在文件中将其引用为:
readfile($_GET['filename'].'.jpg')
关于php - 如何允许用户下载图片(.gif、.png、.jpeg)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12046334/