I’m on a shared host that doesn’t allow Apache X-Sendfile.
I wrote a script to retrieve youtube mp4 urls, and I’d like to make a download for it that doesn’t have the name videoplayback.mp4, rather the video page title instead.
I was thinking about this
[code=php]header(“Content-Type: video/mp4”);
header(‘Content-Disposition: attachment; filename=”‘.basename($file_name).'”‘);
set_time_limit(0);
@ob_end_clean();
@ob_end_flush();
@readfile($mp4_url);
exit;
The problem is that it’s a little extreme just to give the download a name, because the file has to download to my host first and it has to process as a middle man the whole time during the download.
So it got me thinking about cURL. If return transfer is set to 0, like this:
[code=php]header(“Content-Type: video/mp4”);
header(‘Content-Disposition: attachment; filename=”‘.basename($file_name).'”‘);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$mp4_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
curl_exec($ch);
curl_close($ch);
exit;
Does it download directly to the client without going to the server first?