您好 Dreamweaver 说下一行有语法错误。这样对吗?
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
您好 Dreamweaver 说下一行有语法错误。这样对吗?
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
正在使用的 PHP 版本不支持对函数的返回值进行索引。升级到较新的版本,或将其转换为单独的语句。
它可能没有解析 php 5.4,这是理解function()[0]
语法所必需的。
您的 in_array() 参数也不正确
bool in_array ( 混合 $needle , array $haystack [, bool $strict = FALSE ] )
Dreamweaver 是罪魁祸首!
你的代码很好。我试过你的代码,它工作正常。由于您尚未向我们披露变量。 $file
和$allowedExtensions
。我认为这是你必须做的。
此外,if
循环很好。
获取一个新的编辑器,如PHPStorm或Eclipse for PHP
<?php
$file=array('name'=>'test.gif');
$allowedExtensions=array('.gif','.jpg','.png');
if (!in_array(array_reverse(explode(".",strtolower($file['name'])))[0],$allowedExtensions))
{
echo "Valid File Extension";
}
else
{
echo "Invalid File Extension";
}