I don’t know how to write a better title. Feel free to edit. Somehow I didn’t find anything on this:
I have a cURL request from PHP which returns a quicktime file. This works fine if I want to output the stream in the browser’s window. But I want to send it as it were a real file. How can I pass the headers and set it to the script’s output, without the need of storing everything in a variable.
The script looks like this:
if (preg_match('/^[\w\d-]{36}$/',$key)) {
// create url
$url = $remote . $key;
// init cURL request
$ch = curl_init($url);
// set options
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 256);
if (null !== $username) {
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
}
// execute request
curl_exec($ch);
// close
curl_close($ch);
}
I can see the header and content like this, so the request itself is working fine:
HTTP/1.1 200 OK X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2 Java/Oracle Corporation/1.7) Server: GlassFish Server Open Source Edition 3.1.2 Content-Type: video/quicktime Transfer-Encoding: chunked
So with the help of the previous answers I got it to work. Still it has one request to much in my opinion, but maybe someone has a better approach.
The problems that occurred where:
1.) When using cURL like this:
the header didn’t return the content-type, but only
*\*.2.) Using
curl_setopt($ch, CURLOPT_NOBODY, false);got the right content-type but also the whole content itself. So I could store everything in a variable, read the header, send the content. Not really an option somehow.So I had to request the header once using
get_headers($url, 1);before getting the content.3.) Finally, there was the problem that the HTML5-video-tag and the jwPlayer both didn’t want to play ‘index.php’. So with mod_rewrite and setting ‘name.mov’ to ‘index.php’ it worked:
This is the result: