How to have jQuery restrict file types on upload?

You can get the value of a file field just the same as any other field. You can’t alter it, however. So to superficially check if a file has the right extension, you could do something like this: var ext = $(‘#my_file_field’).val().split(‘.’).pop().toLowerCase(); if($.inArray(ext, [‘gif’,’png’,’jpg’,’jpeg’]) == -1) { alert(‘invalid extension!’); }

ReactJS – .JS vs .JSX

There is none when it comes to file extensions. Your bundler/transpiler/whatever takes care of resolving what type of file contents there is. There are however some other considerations when deciding what to put into a .js or a .jsx file type. Since JSX isn’t standard JavaScript one could argue that anything that is not “plain” … Read more

Register a new file type in Android

I’m using this manifest to register (for example) a .stl file type with my application: <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”org.test.core” android:versionCode=”1″ android:versionName=”1.0″> <application android:icon=”@drawable/icon” android:label=”@string/app_name”> <activity android:name=”.Testy” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> <activity android:name=”ThorActivity” android:label=”@string/app_name”> </activity> <activity android:name=”LokiActivity” android:label=”@string/app_name”> </activity> <activity android:name=”OdinActivity” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.VIEW” /> <category android:name=”android.intent.category.DEFAULT” … Read more

Finding the default application for opening a particular file type on Windows

All current answers are unreliable. The registry is an implementation detail and indeed such code is broken on my Windows 8.1 machine. The proper way to do this is using the Win32 API, specifically AssocQueryString: using System.Runtime.InteropServices; [DllImport(“Shlwapi.dll”, CharSet = CharSet.Unicode)] public static extern uint AssocQueryString( AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] … Read more