92445/how-to-check-file-extension-in-upload-form-in-php
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'; }
Hello @kartik,
Using if( $ext !== 'gif') might not be efficient.
Try:
$allowed = array('gif', 'png', 'jpg'); $filename = $_FILES['video_file']['name']; $ext = pathinfo($filename, PATHINFO_EXTENSION); if (!in_array($ext, $allowed)) { echo 'error'; }
PHP is compiled to byte code before ...READ MORE
Hello @kartik, Using property_exists( mixed $class , string $property ...READ MORE
Hello @kartik, You can use instanceof: if ($pdo instanceof PDO) ...READ MORE
Hello, Try this without regular expressions: <?php ...READ MORE
Hey @kartik, First you have to go to ...