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.

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

try basename( parse_url( $url, PHP_URL_PATH ) )