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 ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, Multiple files can be selected and ...READ MORE
Hello @kartik, pathinfo() $path_info = pathinfo('/foo/bar/baz.bill'); echo $path_info['extension']; // "bill" Hope ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.