[Openupload-svn-update] SF.net SVN: openupload:[340] branches/v0.4
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2009-08-28 13:09:35
|
Revision: 340
http://openupload.svn.sourceforge.net/openupload/?rev=340&view=rev
Author: tsdogs
Date: 2009-08-28 13:09:19 +0000 (Fri, 28 Aug 2009)
Log Message:
-----------
Handle mime types server side (if possible), and a couple of checks in the setup script.
Modified Paths:
--------------
branches/v0.4/lib/general.inc.php
branches/v0.4/lib/modules/default/files.inc.php
branches/v0.4/www/setup.inc.php
Modified: branches/v0.4/lib/general.inc.php
===================================================================
--- branches/v0.4/lib/general.inc.php 2009-08-28 12:58:04 UTC (rev 339)
+++ branches/v0.4/lib/general.inc.php 2009-08-28 13:09:19 UTC (rev 340)
@@ -269,7 +269,30 @@
return mail($to,$subject,$msg,$header,'-f "'.$from.'"');
}
+/* tries to use all available methods to determine a file mime type */
+function get_mime_type($file,$type) {
+ global $CONFIG;
+ $mime = $type;
+ if (function_exists('finfo_open')) {
+ if ($CONFIG['mime_magic_file']!='')
+ $finfo = finfo_open(FILEINFO_MIME, $CONFIG['mime_magic_file']);
+ else
+ $finfo = finfo_open(FILEINFO_MIME);
+ $mime = finfo_file($finfo,$file);
+ if (strpos($mime,';')) { /* remove the charset */
+ $mime = substr($mime,0,strpos($mime,';'));
+ }
+ if (strpos($mime,' ')) { /* remove the charset */
+ $mime = substr($mime,0,strpos($mime,' '));
+ }
+ finfo_close($finfo);
+ } else if (function_exists('mime_content_type')) {
+ $mime = mime_content_type($file);
+ } else { /* TODO: try to do it internally ??? */
+ }
+ return $mime;
+}
?>
Modified: branches/v0.4/lib/modules/default/files.inc.php
===================================================================
--- branches/v0.4/lib/modules/default/files.inc.php 2009-08-28 12:58:04 UTC (rev 339)
+++ branches/v0.4/lib/modules/default/files.inc.php 2009-08-28 13:09:19 UTC (rev 340)
@@ -159,9 +159,14 @@
$tmpnamex = $tmpname.'_'.$i;
}
if (isset($_FILES[$u]) and $_FILES[$u]['tmp_name']!='') {
- move_uploaded_file($_FILES[$u]['tmp_name'],$tmpnamex);
+ /* fail if something goes wrong */
+ if (!move_uploaded_file($_FILES[$u]['tmp_name'],$tmpnamex)) {
+ $this->error(tr('Failed moving the file on the server, please check the configuration!'));
+ }
$_SESSION['user']['u'][$i]['tmp']=$tmpnamex;
- $_SESSION['user']['u'][$i]['mime']=$_FILES[$u]['type'];
+ /* get the file mime type, and do not rely on what the browser sends */
+ $mime = get_mime_type($tmpnamex,$_FILES[$u]['type']);
+ $_SESSION['user']['u'][$i]['mime']=$mime;
$_SESSION['user']['u'][$i]['name']=$_FILES[$u]['name'];
$_SESSION['user']['u'][$i]['size']=$_FILES[$u]['size'];
$_SESSION['user']['u'][$i]['ip']=$_SERVER['REMOTE_ADDR'];
Modified: branches/v0.4/www/setup.inc.php
===================================================================
--- branches/v0.4/www/setup.inc.php 2009-08-28 12:58:04 UTC (rev 339)
+++ branches/v0.4/www/setup.inc.php 2009-08-28 13:09:19 UTC (rev 340)
@@ -461,6 +461,17 @@
} else {
msg('Magic Quotes: disabled','ok');
}
+ if (function_exists('finfo_open')) {
+ msg('Fileinfo extension: installed','ok');
+ } else {
+ if (function_exists('mime_content_type')) {
+ msg('mime type php function: available','ok');
+ } else {
+ msg('mime type handling: not available','fail');
+ msg('This could lead problems with bogus browsers!');
+ }
+ msg('For correct mime types handling it\'s suggested to install the Fileinfo');
+ }
if (function_exists('mysql_connect')) {
msg('MYSQL Support: exsists','ok');
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|