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 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败