Get file name of a URL in PHP -
i want file name url. problem it's not ending extension.
for example, http://something.com/1245/65/. on clicking url, pdf file. how store file name of file in variable?
<?php header('content-type: text/plain'); $curl = curl_init('http://localhost/fakefile.php'); curl_setopt($curl, curlopt_header, true); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_customrequest, 'head'); if (($response = curl_exec($curl)) !== false) { if (curl_getinfo($curl, curlinfo_http_code) == '200') { var_dump($response); $redispo = '/^content-disposition: .*?filename=(?<f>[^\s]+|\x22[^\x22]+\x22)\x3b?.*$/m'; if (preg_match($redispo, $response, $mdispo)) { $filename = trim($mdispo['f'],' ";'); echo "filename found: $filename"; } } } curl_close($curl);
that parse content-disposition
line filename=foo.bar information (assuming render file directly out using method.)
Comments
Post a Comment