Skip to content

Instantly share code, notes, and snippets.

@gautamkrishnar
Created December 20, 2015 09:54
Embed
What would you like to do?
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