- Fixed a missing variable bug
This commit is contained in:
1 parent
2a688935cc
commit
79287f28cc
2 files changed
+24
-7
No files matched your search
+23
-5
@@ -14,20 +14,20 @@ class File
|
||||
$beginning = false;
|
||||
$text = array();
|
||||
|
||||
while ($counter && ! $beginning) {
|
||||
while ($counter && !$beginning) {
|
||||
$t = "";
|
||||
|
||||
while ($t !== PHP_EOL) {
|
||||
if(fseek($handle, $pos, SEEK_END) == -1) {
|
||||
if (fseek($handle, $pos, SEEK_END) == -1) {
|
||||
$beginning = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$t = fgetc($handle);
|
||||
$pos --;
|
||||
$pos--;
|
||||
}
|
||||
|
||||
$counter --;
|
||||
$counter--;
|
||||
|
||||
if ($beginning) {
|
||||
rewind($handle);
|
||||
@@ -36,8 +36,26 @@ class File
|
||||
$text[$lines - $counter - 1] = fgets($handle);
|
||||
}
|
||||
|
||||
fclose ($handle);
|
||||
fclose($handle);
|
||||
|
||||
return array_reverse($text);
|
||||
}
|
||||
|
||||
public static function sanitizeFilePath($path) : string
|
||||
{
|
||||
// Remove null bytes
|
||||
$path = str_replace("\0", "", $path);
|
||||
|
||||
$path = str_replace([ "\\", "/" ], DIRECTORY_SEPARATOR, $path);
|
||||
|
||||
$path = preg_replace('#' . DIRECTORY_SEPARATOR . '+#', DIRECTORY_SEPARATOR, $path);
|
||||
|
||||
// Remove . and .. directory traversal attempts
|
||||
$path = preg_replace('#\.{1,2}/#', '', $path);
|
||||
|
||||
$path = trim($path, '/\\');
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user