$file_name = "smith.jpg" // This gives error 'Invalid file extension' What could be the problem?
$whitelist = array('jpg', 'png', 'gif', 'jpeg');
// Validate file extension
if(!in_array(end(explode('.', $file_name)), $whitelist))
HandleError('Invalid file extension');
It would have been better if you used:
echo pathinfo('/www/htdocs/your_image.jpg', PATHINFO_EXTENSION);
use the right functions for what they are made for.
It's a referencing error:
$whitelist = array('jpg', 'png', 'gif', 'jpeg');
// Validate file extension
$parts = explode('.', $file_name);
if(!in_array(end($parts), $whitelist))
{
HandleError('Invalid file extension');
}