preg_replace to remove full path prefix

Use preg_replace to only replace the first instance on a full path to
make it local
Avoids str_replace replacing all instances in the string
This commit is contained in:
Matt Pass
2014-01-15 10:39:31 +00:00
parent 080aaea4f7
commit 58e7c5ec42
2 changed files with 5 additions and 2 deletions

View File

@@ -129,7 +129,8 @@ if (startTab!=top.ICEcoder.selectedTab) {
if (strpos($f,$ICEcoder['bannedFiles'][$i])!==false) {$bFile = true;};
}
// Exclude the folder ICEcoder is running from
$localPath = str_replace(str_replace("\\","/",$docRoot),"",$fullPath);
$rootPrefix = '/'.str_replace("/","\/",preg_quote(str_replace("\\","/",$docRoot))).'/';
$localPath = preg_replace($rootPrefix, '', $fullPath, 1);
if (strpos($localPath, $ICEcoderDir)===0) {
$bFile = true;
}

View File

@@ -79,7 +79,9 @@ if ($_SESSION['loggedIn']) {
}
// Establish the dir ICEcoders running from
$ICEcoderDir = rtrim(str_replace(str_replace("\\","/",$docRoot),"",str_replace("\\","/",dirname(__FILE__))),"/lib");
$ICEcoderDirFullPath = rtrim(str_replace("\\","/",dirname(__FILE__)),"/lib");
$rootPrefix = '/'.str_replace("/","\/",preg_quote(str_replace("\\","/",$docRoot))).'/';
$ICEcoderDir = preg_replace($rootPrefix, '', $ICEcoderDirFullPath, 1);
// Setup our file security vars
$settingsArray = array("findFilesExclude","bannedFiles","allowedIPs");