dougang1605 2013-06-22 17:50
浏览 816
已采纳

cURL保存文件并重命名?

I'm downloading and saving a file from another server to my server, except the file I'm downloading comes attached with an access token.

http://www.example.com/video.mp4?versionId=c_.Qeh.dz.zqPA3zc57HFDKEAmKG3xr2

Loading the following results in a permission error:

http://www.example.com/video.mp4

Problem is, when I cURL with the following code:

$url = 'http://www.example.com/video.mp4?versionId=c_.Qeh.dz.zqPA3zc57HFDKEAmKG3xr2';
$fh = fopen(basename($url), "wb");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_exec($ch);
curl_close($ch);

The file saves as video.mp4?versionId=c_.Qeh.dz.zqPA3zc57HFDKEAmKG3xr2 (with token) and not video.mp4, which means I can't do anything with it afterwards as it's not an .mp4

What's the solution here? I tried

rename(video.mp4?versionId=c_.Qeh.dz.zqPA3zc57HFDKEAmKG3xr2, video.mp4) 

but it requires filenames and the access token is preventing that.

  • 写回答

2条回答 默认 最新

  • doudiecai1572 2013-06-22 17:57
    关注

    Try to use parse_url instead of basename or combine them. Take path from parse_url (without GET params) and then use basename function.

    http://www.php.net/manual/en/function.parse-url.php

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器