PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | $file_url = 'https://webapi.vivotek.com/api/DownloadCenter/Download/global?p1=B96CdIFf5Mh4r7e%2B3jGe1g==&p2=j199RdC0wOvZ8pPmTck8Tg=='; $file_ext = pathinfo($file_url, PATHINFO_EXTENSION); // to get extension $file_name = pathinfo($file_url, PATHINFO_FILENAME); echo $file_ext, '<br />';echo $file_name; $curl = curl_init(); $headers = array(); curl_setopt($curl, CURLOPT_URL, $file_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 50); curl_setopt($curl, CURLOPT_HEADERFUNCTION, function($curl, $header) use (&$headers) { $len = strlen($header); $header = explode(':', $header, 2); if (count($header) < 2) // ignore invalid headers return $len; $headers[strtolower(trim($header[0]))][] = trim($header[1]); return $len; }); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); //curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); //curl_setopt($curl, CURLOPT_FILE, $file); //curl_setopt($curl, CURLOPT_HEADER, 1); $response = curl_exec($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); //$header = substr($response, 0, $header_size); $body = substr($response, $header_size); curl_close($curl); preg_match('/.*filename=[\'\"]?([^\"]+)/', $headers['content-disposition'][0], $matches); if(array_key_exists(1, $matches)) { $params = explode('.', $matches[1]); $file_ext = array_pop($params); $filename = implode('',$params); echo $filename,' ', $file_ext; } |
Recent Posts
Recent Comments
- LogixTree Networks on Localhost showing “Index/of” instead of displaying the Website
- AMANUR RAHMAN on Localhost showing “Index/of” instead of displaying the Website
- Christy on Support Purchase Notes in Order Emails WooCommerce
- LogixTree Networks on Localhost showing “Index/of” instead of displaying the Website
- Sofia on Localhost showing “Index/of” instead of displaying the Website