- fixed handling of failed uploads, eg. > max_upload_size

- fixed encoding of special chars in uploaded file names
This commit is contained in:
Ralf Becker 2010-05-27 13:30:40 +00:00
parent bc2f709a4d
commit 818f57ebcf

View File

@ -63,6 +63,14 @@ class filemanager_select
if (!is_array($content)) if (!is_array($content))
{ {
$content = array(); $content = array();
// recover from a failed upload in CkEditor, eg. > max_uploadsize
if ($_GET['failed_upload'] && $_GET['msg'])
{
$content['msg'] = $_GET['msg'];
$_GET['mode'] = 'open';
$_GET['method'] = 'ckeditor_return';
$_GET['CKEditorFuncNum'] = egw_cache::getSession('filemanager','ckeditorfuncnum');
}
$content['mode'] = $_GET['mode']; $content['mode'] = $_GET['mode'];
if (!in_array($content['mode'],array('open','open-multiple','saveas','select-dir'))) if (!in_array($content['mode'],array('open','open-multiple','saveas','select-dir')))
{ {
@ -79,11 +87,13 @@ class filemanager_select
{ {
if (isset($_GET['CKEditorFuncNum']) && is_numeric($_GET['CKEditorFuncNum'])) if (isset($_GET['CKEditorFuncNum']) && is_numeric($_GET['CKEditorFuncNum']))
{ {
$content['ckeditorfuncnum'] = $_GET['CKEditorFuncNum']; egw_cache::setSession('filemanager','ckeditorfuncnum',
$content['method'] = 'ckeditor_return'; $content['ckeditorfuncnum'] = $_GET['CKEditorFuncNum']);
} }
else else
{
throw new egw_exception_wrong_parameter("chkeditor_return has been specified as a method but some parameters are missing or invalid."); throw new egw_exception_wrong_parameter("chkeditor_return has been specified as a method but some parameters are missing or invalid.");
}
} }
$content['id'] = $_GET['id']; $content['id'] = $_GET['id'];
$content['label'] = isset($_GET['label']) ? $_GET['label'] : lang('Open'); $content['label'] = isset($_GET['label']) ? $_GET['label'] : lang('Open');
@ -118,35 +128,28 @@ class filemanager_select
break; break;
case 'ok': case 'ok':
$copy_result = null; $copy_result = null;
if (isset($content['file_upload']['name'])) if (isset($content['file_upload']['name']) && is_uploaded_file($content['file_upload']['tmp_name']))
{ {
$copy_result = false;
//Set the "content" name filed accordingly to the uploaded file //Set the "content" name filed accordingly to the uploaded file
$content['name'] = $content['file_upload']['name']; // encode chars which special meaning in url/vfs (some like / get removed!)
$content['name'] = egw_vfs::encodePathComponent($content['file_upload']['name']);
//Assemble the "from" and "to" paths and open the files
$from_path = $content['file_upload']['tmp_name'];
$to_path = egw_vfs::concat($content['path'],$content['name']); $to_path = egw_vfs::concat($content['path'],$content['name']);
$from = @fopen($from_path,'r'); $copy_result = (egw_vfs::is_writable($content['path']) || egw_vfs::is_writable($to)) &&
$to = @egw_vfs::fopen($to_path,'w'); copy($content['file_upload']['tmp_name'],egw_vfs::PREFIX.$to_path);
//Perform the copy operation
if ($from && $to)
{
$copy_result = stream_copy_to_stream($from,$to) == $content['file_upload']['size'];
}
} }
//Break on an error condition //Break on an error condition
if ((($content['mode'] == 'open' || $content['mode'] == 'saveas') && ($content['name'] == '')) || ($copy_result === false)) if ((($content['mode'] == 'open' || $content['mode'] == 'saveas') && ($content['name'] == '')) || ($copy_result === false))
{ {
if ($copy_result === false) if ($copy_result === false)
{
$content['msg'] = lang("Error while processing your upload request."); $content['msg'] = lang("Error while processing your upload request.");
}
else else
{
$content['msg'] = lang("The name field may not be empty."); $content['msg'] = lang("The name field may not be empty.");
}
$content['name'] = ''; $content['name'] = '';
break; break;
@ -159,31 +162,33 @@ class filemanager_select
{ {
$files[] = egw_vfs::concat($content['path'],$name); $files[] = egw_vfs::concat($content['path'],$name);
} }
//Add an uploaded file to the files result array2string //Add an uploaded file to the files result array2string
if ($copy_result === true) if ($copy_result === true) $files[] = $to_path;
$files[] = $to_path;
break; break;
case 'select-dir': case 'select-dir':
$files = $content['path']; $files = $content['path'];
break; break;
default: default:
$files = egw_vfs::concat($content['path'],$content['name']); $files = egw_vfs::concat($content['path'],$content['name']);
break; break;
} }
if ($content['method'] != 'ckeditor_return') if ($content['method'] != 'ckeditor_return')
{
$js = ExecMethod2($content['method'],$content['id'],$files); $js = ExecMethod2($content['method'],$content['id'],$files);
}
else else
{
$js = "window.opener.CKEDITOR.tools.callFunction(". $js = "window.opener.CKEDITOR.tools.callFunction(".
$content['ckeditorfuncnum'].",'". $content['ckeditorfuncnum'].",'".
egw::link(egw_vfs::download_url(egw_vfs::concat($content['path'],htmlspecialchars($content['name']))))."',". htmlspecialchars(egw::link(egw_vfs::download_url(egw_vfs::concat($content['path'],$content['name']))))."',".
"'');\nwindow.close();"; "'');\nwindow.close();";
}
header('content-type: text/html; charset=utf-8'); header('Content-type: text/html; charset='.translation::charset());
echo "<html>\n<head>\n<script type='text/javascript'>\n$js\n</script>\n</head>\n</html>\n"; echo "<html>\n<head>\n<script type='text/javascript'>\n$js\n</script>\n</head>\n</html>\n";
$GLOBALS['egw']->common->egw_exit(); common::egw_exit();
} }
} }
elseif(isset($content['apps'])) elseif(isset($content['apps']))