重命名pdf文件以便即时下载 [英] Rename pdf file to be downloaded on fly

查看:71
本文介绍了重命名pdf文件以便即时下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出:服务器上所有已上传的pdf文件都带有时间戳前缀.以后的用户可以再次下载这些文件.这些(丑陋的)文件名将永远不会在服务器上更改.

Given: All the uploaded pdf files on server are prefixed with timestamps. Later user can download these files again. These (ugly)filenames would never change again on server.

问题:当我提供下载PDF文件的选项时,文件名看起来丑陋且冗长.我如何才能将此名称更改为明智的名称,以便用户下载此文件时,名称看起来不会很奇怪?

Question: When I give the option to download PDF file, name of the file looks ugly and lengthy. How can I change this name to something sensible, so that when user downloads this file, name doesn't look weird?

由于无法重命名原始文件,我是否需要进行复制?每个可下载文件都不会产生额外的开销吗?显然删除复制的文件将是又一个额外的步骤吗?

Do I need to make a copy, since renaming the original file is not an option? Wouldn't it be extra overhead for each downloadable file? Obviously deleting the copied file would be another extra step?

一旦在客户端完全下载了文件,是否可以重命名文件?

Is it possible to rename file once file is completely downloaded on client side?

你们有什么建议?

推荐答案

类似以下内容:

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

这篇关于重命名pdf文件以便即时下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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