我创建了一个具有上传功能的网站,并存储在扩展名为.xxx的服务器中,并在每个文件上重命名,然后将原始扩展名和文件名记录到数据库中。
客户 - >下载 - > images.jpg (但在服务器中重命名文件或再次重命名为md5)
如何使用php语言返回带有原始扩展名和文件名的客户端?
你能帮我解决问题吗,谢谢你的英语,对不起。
答案 0 :(得分:0)
您需要一个文件来处理请求,例如downloadimage.php
,并将文件名传递给它,例如downloadimage.php?name=image.jpg
。
取$_GET['name']
并在数据库中查找文件名并提供服务。
然后使用重写来使网址漂亮
RewriteRule /somepath/(.*) /somepath/downloadimage.php?name=$1
因此您可以访问/somepath/image.jpg
答案 1 :(得分:0)
来自PHP文档header
的示例<?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
或在Apache配置中使用RewriteRule
(如Musa所说)来获取
www.yourdomain.com/some-path/image.jpg