/** * Requests headers of remote file to retrieve size without downloading the file * * @param string URL of remote file to retrieve size from */ function fetch_remote_filesize($url) { if (!preg_match('#^((http|ftp)s?):\\/\\/#i', $url, $check)) { $this->set_error('upload_invalid_url'); return false; } require_once DIR . '/includes/class_vurl.php'; $vurl = new vB_vURL($this->registry); $vurl->set_option(VURL_URL, $url); $vurl->set_option(VURL_HEADER, 1); $vurl->set_option(VURL_NOBODY, 1); $vurl->set_option(VURL_USERAGENT, 'vBulletin via PHP'); $vurl->set_option(VURL_CUSTOMREQUEST, 'HEAD'); $vurl->set_option(VURL_RETURNTRANSFER, 1); $vurl->set_option(VURL_CLOSECONNECTION, 1); if ($result = $vurl->exec2() and $length = intval($result['content-length'])) { return $length; } else { return false; } }
/** * Requests headers of remote file to retrieve size without downloading the file * * @param string URL of remote file to retrieve size from */ function fetch_remote_filesize($url) { if (!preg_match('#^((http|ftp)s?):\\/\\/#i', $url, $check)) { $this->set_error('upload_invalid_url'); return false; } require_once DIR . '/includes/class_vurl.php'; $vurl = new vB_vURL($this->registry); $vurl->set_option(VURL_URL, $url); $vurl->set_option(VURL_FOLLOWLOCATION, 1); $vurl->set_option(VURL_HEADER, 1); $vurl->set_option(VURL_NOBODY, 1); $vurl->set_option(VURL_USERAGENT, 'vBulletin via PHP'); $vurl->set_option(VURL_CUSTOMREQUEST, 'HEAD'); $vurl->set_option(VURL_RETURNTRANSFER, 1); $vurl->set_option(VURL_CLOSECONNECTION, 1); $result = $vurl->exec2(); if ($result and $length = intval($result['content-length'])) { return $length; } else { if ($result['http-response']['statuscode'] == "200") { // We have an HTTP 200 OK, but no content-length, return -1 and let VURL handle the max fetch size return -1; } else { return false; } } }