Fix can't create files on shared folder (Windows)

This commit is contained in:
Tobias Sekan 2019-11-29 07:46:39 +01:00 committed by GitHub
parent b820234870
commit f304dd424b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1805,21 +1805,33 @@ class TCPDF_STATIC {
return $ret; return $ret;
} }
/** /**
* Wrapper to use fopen only with local files * Wrapper to use fopen only with local files
* @param filename (string) Name of the file to open * @param string $filename The full path to the file to open
* @param $mode (string) * @param string $mode Acceses type for the file ('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+' or 'e')
* @return Returns a file pointer resource on success, or FALSE on error. * @return resource Returns a file pointer resource on success, or FALSE on error.
* @public static * @public static
*/ */
public static function fopenLocal($filename, $mode) { public static function fopenLocal($filename, $mode)
if (strpos($filename, '://') === false) { {
$filename = 'file://'.$filename; if (strpos($filename, '//') === 0)
} elseif (stream_is_local($filename) !== true) { {
return false; // Share folder on a (windows) server
} // e.g.: "//[MyServerName]/[MySharedFolder]/"
return fopen($filename, $mode); //
} // nothing to change
}
elseif (strpos($filename, '://') === false)
{
$filename = 'file://'.$filename;
}
elseif (stream_is_local($filename) !== true)
{
return false;
}
return fopen($filename, $mode);
}
/** /**
* Check if the URL exist. * Check if the URL exist.