php - 如何允许用户下载图片(.gif、.png、.jpeg)?

标签 php javascript image file download

如何允许用户下载服务器上保存的图片?目标是让用户单击链接并开始下载指定的图像。

Facebook 示例: image download

最佳答案

链接到另一个 .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/

相关文章:

php - 使用 WHERE 子句将数组传递给查询

Javascript 对象字面量。对象[i].变量

javascript - Javascript-我可以一次更改所有音频元素的音量吗?

image - 检测人像图像中的头发颜色

php - Apache 从 RAM 提供文件

php - 图像在移动设备上正确旋转,而不是在桌面上

php - WhereIn 和关系

javascript - 如何在 ASP.NET webforms 项目中缩小和/或合并 *.axd JavaScript 文件?

vb.net - 从 URL 检索图像尺寸

PHP/MySQL 数据库 - 下拉显示图像