发送给用户之前重命名文件? [英] Rename file before sending to user?

查看:92
本文介绍了发送给用户之前重命名文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单和愚蠢的问题,但我不知道该怎么做这样做。

This is probably a very simple and stupid question to ask, but I have no idea how I would go about doing this.

我正在构建一些文件托管功能对于PHP中的客户端。我有一个目录中的文件中央存储库。这是因为如果多个人上传相同的文件,客户端希望保留每个文件的一个副本(基于文件的哈希)。将文件重命名为将其转储到此目录(datetime +某些代码)中以避免文件名冲突。文件的原始名称保存在数据库中。

I am building some file hosting functionality for a client site in PHP. I have a central repository of files in one directory. This is because the client wants to maintain one copy of each file (based on the "hash" of the file) if multiple people upload the same file. Files are renamed before dumping them into this directory (datetime + some code) to avoid filename clashes. The original name(s) of the file are held on the database.

问题出在哪里,是不知道如何将文件重命名为当用户请求下载时的原始文件名?我可以在另一个目录中创建一个临时副本,但我认为这会变得凌乱。我希望有更好的方法。我已经看到另一篇文章:

Where the problem is, is that I have no idea how I would go about renaming the file to the original filename when a user requests to download it? I could create a temporary copy of it in another directory, but I think this is going to get messy. I am hoping there is a better way. I have seen another post with

Response.AppendHeader("content-disposition", "attachment; filename='MyFile.jpg'"); 

但这是在ASP。任何人都可以指向正确的方向?

but that is in ASP. Could anyone point me in the right direction?

非常感谢

Ted

推荐答案

类似:
请参阅标题功能

从该页面的示例中:

<?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');
?>   

这篇关于发送给用户之前重命名文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆