file format validation

On October 2, 2009, in Javascript, Linux, Tips, Tricks, by phpsolutions

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

7 Responses to file format validation

  1. tigla metalica says:

    Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

  2. Anonymous says:

    Hi I found this great site by mistake when i was searching yahoo for this issue, I’ve got to say your website is really helpful Furthermore love the theme, its amazing!. I dont have very much time for it to read your post at the moment but I’ve bookmarked it and as well opted in for your RSS feeds. We are back a day or two. many thanks for an excellent site.

  3. Anonymous says:

    I agree completely together with your conclusions and imagine that you’ve made some excellent points. Also, I prefer customized for specific cultures of one’s site and also the simplicity of navigation. I’ve bookmarked your blog and definately will return often!

  4. Anonymous says:

    I am really thankful towards author of the post to make this lovely and informative article live here for us. We really appreciate ur effort. Maintain the nice work. . . .

  5. Anonymous says:

    I agree completely along with your conclusions and imagine that you’ve made some excellent points. Also, I favor the layout of your site as well as the ease of navigation. I’ve bookmarked your website and can return often!

  6. Anonymous says:

    I am not new to blogging and really appreciate your blog. There is much original content that peaks my interest. I am going to bookmark your site and keep checking you out.

  7. Anonymous says:

    Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which we all need, thanks for all the enthusiasm to offer such helpful information here.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.