Skip to content
Snippets Groups Projects
Commit 44409c3d authored by Andreas Gohr's avatar Andreas Gohr
Browse files

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
parent 82599fb8
No related branches found
No related tags found
No related merge requests found
...@@ -109,6 +109,7 @@ $lang['mediausage'] = 'Use the following syntax to reference this file:'; ...@@ -109,6 +109,7 @@ $lang['mediausage'] = 'Use the following syntax to reference this file:';
$lang['mediaview'] = 'View original file'; $lang['mediaview'] = 'View original file';
$lang['mediaroot'] = 'root'; $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['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['reference'] = 'References for';
$lang['ref_inuse'] = 'The file can\'t be deleted, because it\'s still used by the following pages:'; $lang['ref_inuse'] = 'The file can\'t be deleted, because it\'s still used by the following pages:';
......
...@@ -185,13 +185,24 @@ function media_upload($ns,$auth){ ...@@ -185,13 +185,24 @@ function media_upload($ns,$auth){
global $lang; global $lang;
global $conf; global $conf;
// get file // get file and id
$id = $_POST['id']; $id = $_POST['id'];
$file = $_FILES['upload']; $file = $_FILES['upload'];
// get id
if(empty($id)) $id = $file['name']; 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 // get filename
$id = cleanID($ns.':'.$id);
$fn = mediaFN($id); $fn = mediaFN($id);
// get filetype regexp // get filetype regexp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment