dongyong3590 2014-04-29 16:04
浏览 26
已采纳

在下载之前用PHP重命名文件而不将其保存到服务器?

I have an Adobe Illustrator file (AI) that we currently have a link to on a website which then downloads the file to your computer.

The link looks something like this...
http://domain.com/crm/index.php?entryPoint=fileupload_download&id=22440435-e8ee-bd6f-7612-533b2cd7690f&field=fuaifile_c&type=D1_Designs

What I need to do is rename this file as it downloads.

So I am asking if it is possible to pass this download through another PHP file right before it downloads which would allow me to change the filename on the fly that the user downloads. I cannot change the filename on the server but when it downloads I would like to be able to add some ID numbers to the filename on the fly if this is possibble? Any ideas how to accomplish this without having to resave the image on the server with a new name?

  • 写回答

3条回答 默认 最新

  • doushi5913 2014-04-29 16:09
    关注

    It's ugly, and assumes these aren't "large" files that would exceed your memory_limit, but

    $data = file_get_contents($original_url);
    header('Content-disposition: attachment; filename="new name with id numbers');
    header("Content-type: application/octet-stream");
    echo $data;
    

    You could always enhance this to do byte serving - suck 10k from original url, spit out 10k to user, etc...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里