From 44409c3dd2fce9ef930e0e23d47f1a46e5bc7d1a Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Sat, 27 May 2006 12:03:10 +0200 Subject: [PATCH] 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 --- inc/lang/en/lang.php | 1 + 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 -- GitLab