RSS

file format validation

02 Oct

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

Advertisements
 
2 Comments

Posted by on October 2, 2009 in javascript, Linux, Tips, Tricks

 

Tags: , , , , ,

2 responses to “file format validation

  1. UK Soma z

    December 8, 2009 at 5:10 am

    Interesting theme, I will take part. I know, that together we can come to a right answer. Risperdal USA

     
  2. llc

    January 4, 2011 at 10:23 pm

    Useful blog website, keep me personally through searching it, I am seriously interested to find out another recommendation of it.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: