Advertisement
josh_max

wp_upload_mimes

Dec 6th, 2011
2,765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. /*
  2. ----------------------------------------------------------
  3.  
  4.     Plugin Name:    Extended Mime Types
  5.     Plugin URI: http://blog.tahlequah.k12.ok.us/maxwellja
  6.     Description:    Extends the allowed uploadable MIME types to include a WIDE range of file types. Created specifically for WPMS to allow a wider range of file types network-wide.
  7.     Version:    1.0
  8.  
  9.     Author:     Josh Maxwell (Tahlequah Schools)
  10.     Author URI: http://blog.tahlequah.k12.ok.us/maxwellja
  11.  
  12. ----------------------------------------------------------
  13. */
  14.  
  15. // Add the filter
  16. add_filter('upload_mimes', 'tqps_extended_mime_types');
  17.  
  18. // Function to add mime types
  19. function tqps_extended_mime_types ( $mime_types=array() ) {
  20.  
  21.     // add your extension & app info to mime-types.txt in this format
  22.     //   doc,doct application/msword
  23.     //   pdf application/pdf
  24.     // etc...
  25.     $file = '/extended-mime-types/mime-types.txt';
  26.     $file = plugins_url() . $file;
  27.     $mime_file_lines = file($file);
  28.  
  29.     foreach ($mime_file_lines as $line) {
  30.         //Catch all sorts of line endings - CR/CRLF/LF
  31.         $mime_type = explode(" ",rtrim(rtrim($line,"\n"),"\r"));
  32.         $mime_types[$mime_type[0]] = $mime_type[1];
  33.     }
  34.  
  35.     // add as many as you like
  36.     return $mime_types;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement