In my form there is an input to re-name the file. When they choose a file to upload it is checked to make sure it is only a .pdf file. I am trying to check the input to make sure they did not add a file extension to the new name. I am trying to check for any variation of ‘pdf’ Here is what I have but is there a better way to do this. Any help welcome, Thanks
<?php
function get_file_extension($pdf)
{
return substr(strrchr($pdf,'.'),0);
}
$pdf = "test.pdf";
$test = strstr($pdf, '.');
$pdf_ext = array('.pdf','.PDF','.Pdf','.PDf','.pdF','.pDf','.PdF','.PdF');
$test = get_file_extension($pdf);
if($test == in_array($test,$pdf_ext)) {
echo 'you do not a .pdf';
} else {
echo 'name ok';
}
?>
Simply use
strtolowerorstrtoupper:Or