static function GetRemoteFileInfo($url, $follow_redirects = 5) { wpfb_loadclass('Download'); if (parse_url($url, PHP_URL_SCHEME) === 'file' && is_readable($url)) { return array('name' => basename($url), 'size' => filesize($url), 'type' => WPFB_Download::GetFileType($url), 'time' => filemtime($url)); } $info = array(); $path = parse_url($url, PHP_URL_PATH); require_once ABSPATH . WPINC . "/http.php"; $response = wp_remote_head($url, array_merge(array('timeout' => 10))); if (is_wp_error($response)) { return $response; } $headers = wp_remote_retrieve_headers($response); if (empty($headers)) { return new WP_Error('get_remote_file_info', 'Headers not set!'); } if ($response['response']['code'] >= 300 && $response['response']['code'] <= 399) { if (empty($headers['location'])) { return new WP_Error('get_remote_file_info', "HTTP {$response['code']} but no location header!"); } if ($follow_redirects > 0) { return self::GetRemoteFileInfo($headers['location'], $follow_redirects - 1); } $info['location'] = $headers['location']; } $info['size'] = isset($headers['content-length']) ? $headers['content-length'] : -1; $info['type'] = isset($headers['content-type']) ? strtolower($headers['content-type']) : null; if (($p = strpos($info['type'], ';')) > 0) { $info['type'] = substr($info['type'], 0, $p); } $info['time'] = isset($headers['last-modified']) ? @strtotime($headers['last-modified']) : 0; $info['etag'] = isset($headers['etag']) ? trim($headers['etag'], '"') : ''; $info['_response'] = $response; // check for filename header if (!empty($headers['content-disposition'])) { $matches = array(); if (preg_match('/filename="?([^"]+)"?/', $headers['content-disposition'], $matches) == 1) { $info['name'] = $matches[1]; } } if (empty($info['name'])) { $info['name'] = basename($path); } // compare extension type with http header content-type, if they are different deterime proper extension from http content-type $exType = WPFB_Download::GetFileType($info['name']); if ($exType != $info['type'] && ($e = WPFB_Download::FileType2Ext($info['type'])) != null) { $info['name'] .= '.' . $e; } return $info; }
static function GetRemoteFileInfo($url) { wpfb_loadclass('Download'); if (parse_url($url, PHP_URL_SCHEME) === 'file' && is_readable($url)) { return array('name' => basename($url), 'size' => filesize($url), 'type' => WPFB_Download::GetFileType($url), 'time' => filemtime($url)); } $info = array(); $path = parse_url($url, PHP_URL_PATH); $headers = self::HttpGetHeaders($url); if (empty($headers)) { return null; } $info['size'] = isset($headers['content-length']) ? $headers['content-length'] : -1; $info['type'] = isset($headers['content-type']) ? strtolower($headers['content-type']) : null; $info['time'] = isset($headers['last-modified']) ? @strtotime($headers['last-modified']) : 0; // check for filename header if (!empty($headers['content-disposition'])) { $matches = array(); if (preg_match('/filename="(.+)"/', $headers['content-disposition'], $matches) == 1) { $info['name'] = $matches[1]; } } if (empty($info['name'])) { $info['name'] = basename($path); } // compare extension type with http header content-type, if they are different deterime proper extension from http content-type $exType = WPFB_Download::GetFileType($info['name']); if ($exType != $info['type'] && ($e = WPFB_Download::FileType2Ext($info['type'])) != null) { $info['name'] .= '.' . $e; } return $info; }
static function GetRemoteFileInfo($url) { wpfb_loadclass('Download'); if (parse_url($url, PHP_URL_SCHEME) === 'file' && is_readable($url)) { return array('name' => basename($url), 'size' => filesize($url), 'type' => WPFB_Download::GetFileType($url), 'time' => filemtime($url)); } $info = array(); $path = parse_url($url, PHP_URL_PATH); require_once ABSPATH . WPINC . "/http.php"; $response = wp_remote_head($url, array('timeout' => 10)); if (is_wp_error($response)) { return $response; } $headers = wp_remote_retrieve_headers($response); if (empty($headers)) { return new WP_Error('get_remote_file_info', 'Headers not set!'); } $info['size'] = isset($headers['content-length']) ? $headers['content-length'] : -1; $info['type'] = isset($headers['content-type']) ? strtolower($headers['content-type']) : null; $info['time'] = isset($headers['last-modified']) ? @strtotime($headers['last-modified']) : 0; // check for filename header if (!empty($headers['content-disposition'])) { $matches = array(); if (preg_match('/filename="(.+)"/', $headers['content-disposition'], $matches) == 1) { $info['name'] = $matches[1]; } } if (empty($info['name'])) { $info['name'] = basename($path); } // compare extension type with http header content-type, if they are different deterime proper extension from http content-type $exType = WPFB_Download::GetFileType($info['name']); if ($exType != $info['type'] && ($e = WPFB_Download::FileType2Ext($info['type'])) != null) { $info['name'] .= '.' . $e; } return $info; }