diff options
author | Andreas Gohr <andi@splitbrain.org> | 2006-05-27 12:03:10 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2006-05-27 12:03:10 +0200 |
commit | 44409c3dd2fce9ef930e0e23d47f1a46e5bc7d1a (patch) | |
tree | c66a3f6d0086c1fd7a23533ca908482671f1fcc3 | |
parent | 82599fb8990eca91a3f0d17388f6c8457bbcf5b7 (diff) | |
download | rpg-44409c3dd2fce9ef930e0e23d47f1a46e5bc7d1a.tar.gz rpg-44409c3dd2fce9ef930e0e23d47f1a46e5bc7d1a.tar.bz2 |
be clever about extensions on upload
This patch makes it possible to enter filenames without an
extension in the upload as field when the uploaded file it
self has a known extension.
It also prints a warning when an extension was changed by
the user.
darcs-hash:20060527100310-7ad00-cf2abb4b9730e54b96c6ba24b2a999011cfb834a.gz
-rw-r--r-- | inc/lang/en/lang.php | 1 | ||||
-rw-r--r-- | inc/media.php | 17 |
2 files changed, 15 insertions, 3 deletions
diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index 031ce4dab..b80668ea3 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -109,6 +109,7 @@ $lang['mediausage'] = 'Use the following syntax to reference this file:'; $lang['mediaview'] = 'View original file'; $lang['mediaroot'] = 'root'; $lang['mediaupload'] = 'Upload a file to the current namespace here. To create subnamespaces, prepend them to your "Upload as" filename separated by colons.'; +$lang['mediaextchange'] = 'Filextension changed from .%s to .%s!'; $lang['reference'] = 'References for'; $lang['ref_inuse'] = 'The file can\'t be deleted, because it\'s still used by the following pages:'; diff --git a/inc/media.php b/inc/media.php index 05f22719f..792064c0a 100644 --- a/inc/media.php +++ b/inc/media.php @@ -185,13 +185,24 @@ function media_upload($ns,$auth){ global $lang; global $conf; - // get file + // get file and id $id = $_POST['id']; $file = $_FILES['upload']; - // get id if(empty($id)) $id = $file['name']; - $id = cleanID($ns.':'.$id); //FIXME handle relative and absolute names here + + // check extensions + list($fext) = mimetype($file['name']); + list($iext) = mimetype($id); + if($fext && !$iext){ + // no extension specified in id - readd original one + $id .= '.'.$fext; + }elseif($fext && $fext != $iext){ + // extension was changed, print warning + msg(sprintf($lang['mediaextchange'],$fext,$iext)); + } + // get filename + $id = cleanID($ns.':'.$id); $fn = mediaFN($id); // get filetype regexp |