Support remote files in file_exists

This commit is contained in:
nicolaasuni 2018-09-22 12:50:04 +01:00
parent b6651409f0
commit aee50eb2bf
4 changed files with 40 additions and 8 deletions

View File

@ -1,3 +1,6 @@
6.2.24
- Support remote urls when checking if file exists.
6.2.23
- Simplify file_exists function.

View File

@ -1,6 +1,6 @@
{
"name": "tecnickcom/tcpdf",
"version": "6.2.23",
"version": "6.2.24",
"homepage": "http://www.tcpdf.org/",
"type": "library",
"description": "TCPDF is a PHP class for generating PDF documents and barcodes.",

View File

@ -55,7 +55,7 @@ class TCPDF_STATIC {
* Current TCPDF version.
* @private static
*/
private static $tcpdf_version = '6.2.23';
private static $tcpdf_version = '6.2.24';
/**
* String alias for total number of pages.
@ -1821,6 +1821,31 @@ class TCPDF_STATIC {
return fopen($filename, $mode);
}
/**
* Check if the URL exist.
* @param url (string) URL to check.
* @return Returns TRUE if the URL exists; FALSE otherwise.
* @public static
*/
public static function url_exists($url) {
$crs = curl_init();
curl_setopt($crs, CURLOPT_URL, $url);
curl_setopt($crs, CURLOPT_NOBODY, true);
curl_setopt($crs, CURLOPT_FAILONERROR, true);
if ((ini_get('open_basedir') == '') && (!ini_get('safe_mode'))) {
curl_setopt($crs, CURLOPT_FOLLOWLOCATION, true);
}
curl_setopt($crs, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($crs, CURLOPT_TIMEOUT, 30);
curl_setopt($crs, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($crs, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($crs, CURLOPT_USERAGENT, 'tc-lib-file');
curl_exec($crs);
$code = curl_getinfo($crs, CURLINFO_HTTP_CODE);
curl_close($crs);
return ($code == 200);
}
/**
* Wrapper for file_exists.
* Checks whether a file or directory exists.
@ -1830,10 +1855,14 @@ class TCPDF_STATIC {
* @public static
*/
public static function file_exists($filename) {
if (strpos($filename, '://') && (preg_match('|^https?://|', $filename) !== 1)) {
return false;
$httpmode = (preg_match('|^https?://|', $filename) == 1);
if (!$httpmode && strpos($filename, '://')) {
return false; // only support http and https wrappers for security reasons
}
return @file_exists($filename);
if (@file_exists($filename) || ($httpmode && self::url_exists($filename))) {
return true;
}
return false;
}
/**

View File

@ -1,7 +1,7 @@
<?php
//============================================================+
// File name : tcpdf.php
// Version : 6.2.23
// Version : 6.2.24
// Begin : 2002-08-03
// Last Update : 2018-09-14
// Author : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
@ -104,7 +104,7 @@
* Tools to encode your unicode fonts are on fonts/utils directory.</p>
* @package com.tecnick.tcpdf
* @author Nicola Asuni
* @version 6.2.23
* @version 6.2.24
*/
// TCPDF configuration
@ -128,7 +128,7 @@ require_once(dirname(__FILE__).'/include/tcpdf_static.php');
* TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
* @package com.tecnick.tcpdf
* @brief PHP class for generating PDF documents without requiring external extensions.
* @version 6.2.23
* @version 6.2.24
* @author Nicola Asuni - info@tecnick.com
* @IgnoreAnnotation("protected")
* @IgnoreAnnotation("public")