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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效