如何准备主题字符串以从$allowed
数组中伪造preg_match检查扩展?目标是使用扩展名不在允许的数组中的文件名。我尝试了一些技巧,比如UTF8编码和新行注入,但无法实现任务目标。谢谢你,很抱歉我的英语
$allowed = array('tst', 'dll');
$filename = basename($test);
if (preg_match('#'.(.+)$#', $filename, $matches) && isset($matches[1]) && !in_array($matches[1], $allowed))
die("Extension not allowed!");
echo $ext;
pathinfo
是您想要的
PHP.net
$file_parts = pathinfo($filename);
switch($file_parts['extension'])
{
case "jpg":
break;
case "exe":
break;
case "": // Handle file extension for files ending in '.'
case NULL: // Handle no file extension
break;
}
这应该是一个很好的例子。