El Dorado

A full-stack community web application written in Ruby/Rails
Patch to use fileinfo for setting proper MIME type « Wordpress « almost effortless
 
Sun, 23 Oct 2005, 10:38pm #1
pjl
New member
Registered: Oct, 2005
Last visit: Mon, 24 Oct 2005
Posts: 2

--- secure-files.php-orig Mon Oct 24 02:51:59 2005
+++ secure-files.php Mon Oct 24 03:22:15 2005
@@ -70,7 +70,21 @@
$downloadfile = $sf_directory . basename($downloadfile);
if (is_file($downloadfile)) {
header('Content-Description: File Transfer');
- header('Content-Type: application/force-download');
+ if (!extension_loaded('fileinfo')) {
+ if (!dl('fileinfo.' . PHP_SHLIB_SUFFIX)) {
+ header('Content-Type: application/force-download');
+ }
+
+ $res = finfo_open(FILEINFO_MIME);
+ $mime_type = finfo_file($res, $downloadfile);
+ finfo_close($res);
+ header('Content-Type: ' . $mime_type);
+ } else {
+ $res = finfo_open(FILEINFO_MIME);
+ $mime_type = finfo_file($res, $downloadfile);
+ finfo_close($res);
+ header('Content-Type: ' . $mime_type);
+ }
header('Content-Length: ' . filesize($downloadfile));
header('Content-Disposition: attachment; filename="' . basename($downloadfile).'"');
@readfile($downloadfile);
@@ -197,4 +211,4 @@
add_action('admin_head', 'sf_admin_head_js');
add_action('template_redirect', 'sf_downloads');

-?>
+?>

If the extension is not installed, it should fall back to the default one. Hope you might find it useful.

If you want the patch as an email attachment, shoot me an email and I'll be happy to resend it 'cause it looks like the BB software converts tabs to spaces and I can't seem to be able to attach a file.

Regards,

Pat

Offline
Sun, 23 Oct 2005, 10:49pm #2
pjl
New member
Registered: Oct, 2005
Last visit: Mon, 24 Oct 2005
Posts: 2

Not to be a tool and reply to my own post, but this is a better patch...

--- secure-files.php-orig Mon Oct 24 03:43:49 2005
+++ secure-files.php Mon Oct 24 03:41:45 2005
@@ -70,7 +70,20 @@
$downloadfile = $sf_directory . basename($downloadfile);
if (is_file($downloadfile)) {
header('Content-Description: File Transfer');
- header('Content-Type: application/force-download');
+
+ if (!extension_loaded('fileinfo')) {
+ if (!dl('fileinfo.' . PHP_SHLIB_SUFFIX)) {
+ header('Content-Type: application/force-download');
+ }
+ }
+
+ if (extension_loaded('fileinfo')) {
+ $res = finfo_open(FILEINFO_MIME);
+ $mime_type = finfo_file($res, $downloadfile);
+ finfo_close($res);
+ header('Content-Type: ' . $mime_type);
+ }
+
header('Content-Length: ' . filesize($downloadfile));
header('Content-Disposition: attachment; filename="' . basename($downloadfile).'"');
@readfile($downloadfile);
@@ -197,4 +210,4 @@
add_action('admin_head', 'sf_admin_head_js');
add_action('template_redirect', 'sf_downloads');

-?>
+?>

Regards,

Pat

Offline
Thu, 27 Oct 2005, 6:55pm #3
Trevor
Administrator
Wait-ill-fix-it
Registered: Sep, 2005
Last visit: 41 minutes ago
Posts: 240

Hey, Pat. I'm going to email you about this and look into updating the plugin. Sorry I didn't respond earlier - I just saw the message. (I thought I was logged into the Forum and would see new posts highlighted, but I had deleted my cookies a while ago and forgot to re-login!)

Offline