Skip to content

Commit

Permalink
Fix can't create files on shared folder (Windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasSekan committed Nov 29, 2019
1 parent b820234 commit f304dd4
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions htdocs/includes/tecnickcom/tcpdf/include/tcpdf_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1805,21 +1805,33 @@ public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $f
return $ret;
}

/**
* Wrapper to use fopen only with local files
* @param filename (string) Name of the file to open
* @param $mode (string)
* @return Returns a file pointer resource on success, or FALSE on error.
* @public static
*/
public static function fopenLocal($filename, $mode) {
if (strpos($filename, '://') === false) {
$filename = 'file://'.$filename;
} elseif (stream_is_local($filename) !== true) {
return false;
}
return fopen($filename, $mode);
}
/**
* Wrapper to use fopen only with local files
* @param string $filename The full path to the file to open
* @param string $mode Acceses type for the file ('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+' or 'e')
* @return resource Returns a file pointer resource on success, or FALSE on error.
* @public static
*/
public static function fopenLocal($filename, $mode)
{
if (strpos($filename, '//') === 0)
{
// Share folder on a (windows) server
// e.g.: "//[MyServerName]/[MySharedFolder]/"
//
// 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.
Expand Down

0 comments on commit f304dd4

Please sign in to comment.