Skip to content

Commit

Permalink
Merge pull request #166 from arcfieldOSS/final
Browse files Browse the repository at this point in the history
Bug Fixes in file writing and dir naming.
  • Loading branch information
khoaofgod committed Dec 30, 2015
2 parents b2617f1 + 0f1a13b commit 704197e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion phpfastcache/3.0.0/drivers/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions phpfastcache/3.0.0/phpfastcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 704197e

Please sign in to comment.