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.

查看全部
dougang1605
dougang1605
2013/06/22 17:50
  • curl
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复