I check file extension for upload or not uploaded. my i.e methods worked but now i need to understand, my methods (pathinfo) is true ? another better and faster way ?! Thanks
$filename = $_FILES['video_file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if( $ext !== 'gif' || $ext !== 'png' || $ext !== 'jpg' ) {echo 'error';}
Checking file extension is not considered best practice, preferred method of accomplishing this task is by checking the files mime type.
From PHP:
The above example will output something similar to which you should be checking.
Although mime-types can also be tricked (edit the first few bytes of a file and modify the magic numbers) but it's harder than editing a filename. So you can never be 100% sure what that file type actually is, and care should be taken about handling files uploaded/emailed by your users.
Using
if( $ext !== 'gif'
) might not be efficient what if you allow like 20 different extensionsTry
How to validate file extension (jpg/jpeg only) on a form before upload takes place. A variation on another posted answer here with an included data filter which may be useful when evaluating other posted form values. Note: error is left blank if empty as this was an option for my users, not a requirement.
Your html will look something like this;
use this function
Not sure if this would have a faster computational time, but another option...
i think this might work for you