Determine file type in Ruby

There is a ruby binding to libmagic that does what you need. It is available as a gem named ruby-filemagic: gem install ruby-filemagic Require libmagic-dev. The documentation seems a little thin, but this should get you started: $ irb irb(main):001:0> require ‘filemagic’ => true irb(main):002:0> fm = FileMagic.new => #<FileMagic:0x7fd4afb0> irb(main):003:0> fm.file(‘foo.zip’) => “Zip archive … Read more

Upload DOC or PDF using PHP

Don’t use the [‘type’] parameter to validate uploads. That field is user-provided, and can be trivially forged, allowing ANY type of file to be uploaded. The same goes for the [‘name’] parameter – that’s the name of the file as provided by the user. It is also trivial to forge, so the user’s sending nastyvirus.exe … Read more

How do I determine the extension(s) associated with a MIME type in PHP?

Not built-in, but it’s not terribly hard to roll your own: function system_extension_mime_types() { # Returns the system MIME type mapping of extensions to MIME types, as defined in /etc/mime.types. $out = array(); $file = fopen(‘/etc/mime.types’, ‘r’); while(($line = fgets($file)) !== false) { $line = trim(preg_replace(‘/#.*/’, ”, $line)); if(!$line) continue; $parts = preg_split(‘/\s+/’, $line); if(count($parts) … Read more

Multiple file types in vim

You can specify to use multiple filetypes at the same time. For example: :setfiletype html.php But most of filetype plugings and syntax files are not designed for such cases. See also :help ‘filetype’

Which Visual C++ file types should be committed to version control?

Yes: cpp: source code filters: project file h: source code ico: resource rc: resource script rc2: resource script sln: project file txt: project element vcxproj: project file No: aps: last resource editor state exe: build result idb: build state ipch: build helper lastbuildstate: build helper lib: build result. Can be 3rd party log: build log … Read more

How do I get File Type Information based on extension? (not MIME) in c#

Thanks Dan, Alright.. This answers the first question I had. Sadly not the second. Note: Not everything prints.. Credits to PInvoke.net using System; using System.Runtime.InteropServices; using System.Text; using System.Diagnostics; namespace WindowsFormsApplication1 { static class Program { [DllImport(“Shlwapi.dll”, SetLastError = true, CharSet = CharSet.Auto)] static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] … Read more