Skip to content

Instantly share code, notes, and snippets.

@gautamkrishnar
Created December 20, 2015 09:54
Show Gist options
  • Save gautamkrishnar/bf7f3e00ad9b3703e7ae to your computer and use it in GitHub Desktop.
Save gautamkrishnar/bf7f3e00ad9b3703e7ae to your computer and use it in GitHub Desktop.
file extension fiter for file upload
//upload code
$filename=$_FILE['name']['filename_in_html']; //you can change this with your filename
$allowed='png,jpg'; //which file types are allowed seperated by comma
$extension_allowed= explode(',', $allowed);
$file_extension= pathinfo($filename, PATHINFO_EXTENSION);
if(array_search($file_extension, $extension_allowed))
{
echo "$extension_allowed allowed for uploading file";
}
else
{
echo "$extension_allowed is not allowed for uploading file";
}
//Rem $filename=$_FILE['name']['filename_in_html']; //you can change this with your filename
$allowed='png,jpg'; //which file types are allowed seperated by comma
$extension_allowed= explode(',', $allowed);
$file_extension= pathinfo($filename, PATHINFO_EXTENSION);
if(array_search($file_extension, $extension_allowed))
{
echo "$extension_allowed allowed for uploading file";
}
else
{
echo "$extension_allowed is not allowed for uploading file";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment