file format validation


Hits: 1607  

Below is the code to check file type in javascript..

<script type=”text/javascript” language=”javascript”>

function isImage(file) {
var image    = /\.(jpg|jpeg|bmp|gif|png|jpe)$/i;
if (image.test(file))
return true;
else
return false;
}

function isAudio(file) {
var audio    = /\.(mp3|wav|mid|midi|mp2|ul|ra|m3u|ram|rm)$/i;
if (audio.test(file))
return true;
else
return false;
}

function isArchive(file) {
var archive    = /\.(zip|rar)$/i;
if (archive.test(file))
return true;
else
return false;
}

function isVideo(file) {
var video = /\.(mov|mpg|mpeg|avi|asf|wmv|mpe|3gp|swf)$/i;
if (video.test(file))
return true;
else
return false;
}

</script>

If you really want to validate uploaded file… you have to use “Mediainfo” on linux to check/validate file mime type.

MediaInfo provides technical and tag information about a video or audio file.

# mediainfo --help

Features/Download: http://mediainfo.sourceforge.net/en/Download

Mediainfo: http://mediainfo.sourceforge.net/en

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch