WordPress.org

Plugin Directory

Changeset 468838


Ignore:
Timestamp:
11/28/11 23:30:09 (2 years ago)
Author:
isaacchapman
Message:

Adding 0.4 tag with (arguably) improved MIME type detection

Location:
htaccess-secure-files
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • htaccess-secure-files/trunk/dl.php

    r458078 r468838  
    118118// Set the headers 
    119119$filetype = wp_check_filetype($_SERVER['REQUEST_URI']); 
     120$content_type = $filetype['type']; 
     121if (!$content_type) { 
     122    // The content type could not be set using WordPress's built-in (or plugin edited) MIME types, get from PHP if available 
     123    if (function_exists('finfo_open')) { 
     124        // Fileinfo PECL extension installed 
     125        $finfo = finfo_open(FILEINFO_MIME_TYPE); 
     126        $mime_type = finfo_file($finfo, $file); 
     127        finfo_close($finfo); 
     128        if ($mime_type && is_string($mime_type) && !empty($mime_type)) { 
     129            $content_type = $mime_type;  
     130        } 
     131    } 
     132    if (!$content_type && function_exists('mime_content_type')) { 
     133        // mime_content_type is deprecated 
     134        $mime_type = mime_content_type($file); 
     135        if ($mime_type && is_string($mime_type) && !empty($mime_type)) { 
     136            $content_type = $mime_type;  
     137        } 
     138    } 
     139    if (!$content_type) { 
     140        $content_type = 'application/octet-stream';  
     141    } 
     142} 
    120143$filestat = stat($file); 
    121144header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $filestat['mtime']) . ' GMT'); 
    122145header('Etag: ' . sprintf('"%x-%x-%s"', $filestat['ino'], $filestat['size'], base_convert(str_pad($filestat['mtime'], 16, '0'), 10, 16))); 
    123146header('Content-Length: ' . $filestat['size']); 
    124 if (!$filetype || !is_array($filetype) || !isset($filetype['type']) || !$filetype['type']) { 
    125     header('Content-Type: application/octet-stream'); 
    126 } else { 
    127     header('Content-Type: ' . $filetype['type']); 
    128 } 
     147header('Content-Type: ' . $content_type); 
    129148 
    130149// Send the file 
  • htaccess-secure-files/trunk/readme.txt

    r458078 r468838  
    44Requires at least: 3.2.1 
    55Tested up to: 3.2.1 
    6 Stable tag: 0.3 
     6Stable tag: 0.4 
    77 
    88Allows securing files in WP's media library to be only accessible to users with specific roles, capabilities, or IP addresses. 
     
    2929== Changelog == 
    3030 
     31= 0.4 = 
     32* MIME/Content-type detection routine expanded (in order of priority): 1) Use WordPress's built-in (or plugin modified) MIME types. 2) Use Fileinfo PECL extension if installed. 3) Check with mime_content_type (deprecated). 4) Fallback to 'application/octet-stream'. 
     33 
    3134= 0.3 = 
    3235* "Denied access response" is now customizable: WordPress login, 403 Forbidden, 404 Not Found, or custom redirect. 
Note: See TracChangeset for help on using the changeset viewer.