Image verification in PHP

cyberphant0m

Member
Oct 21, 2003
99
0
0
I am trying to create a function which would take a filename and determine whether or not it is an image based on a defined array or file extensions:

function IsImage($filename)
{
$file_info = pathinfo($filename);
$file_extension = $file_info["extension"];
if (!in_array($file_extension, $file_exts)) return false;
else return true;
}

This would search an array of file extensions for the extension of the passed in variable. But when I try the function, I get the error

Warning
: Wrong datatype for second argument in call to in_array in <B>c:\apache\htdocs\phpgallery\index.php</B> on line <B>71</B>
 

cyberphant0m

Member
Oct 21, 2003
99
0
0
UPDATE: Ive stuck in some gettype() statements to trace back the datatypes of the variables involved, and for some reason, a variable that started off as an array turns into a NULL datatype, which is why im getting the error... Is there a way that I have to pass an array into a function?
 

Extrarius

Senior member
Jul 8, 2001
259
0
0
Even if it is global, you haven't declared it. You have to say that the variable is global inside the function so it knows where to get it from, using a line like "global $file_exts;" at the top of the function.