Wie bekomme ich den Dateinamen aus header-Verwendung von curl in php?

wie kann ich bestimmen Sie den Dateinamen in der Kopfzeile, wenn ich mit php. Schloss an:

<?php
/*
This is usefull when you are downloading big files, as it
will prevent time out of the script :
*/
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....

$fp = fopen (dirname(__FILE__) . '/tempfile', 'w+');//This is the file where we save the information
$ch = curl_init('http://www.example.com/getfile.php?id=4456'); //Here is the file we are downloading

/*
    the server get me an header 'Content-Disposition: attachment; filename="myfile.pdf"'

    i want get 'myfile.pdf' from headers. how can i get it ?
*/

$fileNameFromHeader = '?????????????';

curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);

//rename file
rename(dirname(__FILE__) . '/tempfile', dirname(__FILE__) . $fileNameFromHeader);
InformationsquelleAutor sweb | 2010-11-03
Schreibe einen Kommentar