diff --git a/phpfastcache/3.0.0/drivers/files.php b/phpfastcache/3.0.0/drivers/files.php index abbe62209..c059467d0 100644 --- a/phpfastcache/3.0.0/drivers/files.php +++ b/phpfastcache/3.0.0/drivers/files.php @@ -91,7 +91,7 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) { * because first-to-lock wins and the file will exist before the writer attempts * to write. */ - if($toWrite == true && !@file_exists($tmp_path && !@file_exists($file_path))) { + if($toWrite == true && !@file_exists($tmp_path) && !@file_exists($file_path)) { try { $f = @fopen($tmp_path, "c"); if ($f) { diff --git a/phpfastcache/3.0.0/phpfastcache.php b/phpfastcache/3.0.0/phpfastcache.php index 8db4a3321..2cee7ea2b 100644 --- a/phpfastcache/3.0.0/phpfastcache.php +++ b/phpfastcache/3.0.0/phpfastcache.php @@ -163,13 +163,14 @@ public static function getPath($skip_create_path = false, $config) { if($securityKey == "" || $securityKey == "auto") { $securityKey = self::$config['securityKey']; if($securityKey == "auto" || $securityKey == "") { - $securityKey = isset($_SERVER['HTTP_HOST']) ? ltrim(strtolower($_SERVER['HTTP_HOST']),"www.") : "default"; - $securityKey = preg_replace("/[^a-zA-Z0-9]+/","",$securityKey); + $securityKey = isset($_SERVER['HTTP_HOST']) ? preg_replace('/^www./','',strtolower($_SERVER['HTTP_HOST'])) : "default"; } } if($securityKey != "") { $securityKey.= "/"; } + + $securityKey = self::cleanFileName($securityKey); $full_path = $path."/".$securityKey; $full_pathx = md5($full_path); @@ -199,6 +200,12 @@ public static function getPath($skip_create_path = false, $config) { return realpath($full_path); } + + public static function cleanFileName($filename) { + $regex = ['/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/','/\.$/','/^\./']; + $replace = ['-','','']; + return preg_replace($regex,$replace,$filename); + } public static function __setChmodAuto($config) {