I check the file extension for upload or not uploaded. My example methods worked, but now I need to understand if my methods (using pathinfo
) is true. Is there another better and faster way?
$filename = $_FILES['video_file']['name']; $ext = pathinfo($filename, PATHINFO_EXTENSION); if ($ext !== 'gif' || $ext !== 'png' || $ext !== 'jpg') { echo 'error'; }
Using if( $ext !== 'gif'
) might not be efficient. What if you allow like 20 different extensions?
Try:
$allowed = array('gif', 'png', 'jpg'); $filename = $_FILES['video_file']['name']; $ext = pathinfo($filename, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { echo 'error'; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With