<?php
$curdir = (isset($params['curdir']) ? $params['curdir'] : "");
$browsefiles = (isset($params['browse']) ? $params['browse'] : 'any');



if (isset($_FILES[$id."upload"]))
	$fileinfo = $_FILES[$id."upload"];
else $this->Redirect($id, 'browse', $returnid, array('curdir'=>$curdir, 'browse'=>$browsefiles,'error'=>$this->lang('error_nofiletoupload')));

if (isset($fileinfo['error']) && $fileinfo['error']!=0)
	$this->Redirect($id, 'browse', $returnid, array('curdir'=>$curdir, 'browse'=>$browsefiles,'error'=>$this->lang('error_unabletoupload')));

if ($fileinfo['size']>$config["max_upload_size"])
	$this->Redirect($id, 'browse', $returnid, array('curdir'=>$curdir, 'browse'=>$browsefiles,'error'=>$this->lang('error_filetoobig')));


if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $fileinfo['name']) ||  $fileinfo['name']=="" )
	$this->Redirect($id, 'browse', $returnid, array('curdir'=>$curdir, 'browse'=>$browsefiles,'error'=>$this->lang('error_invalidfilename')));

if( !cms_move_uploaded_file($fileinfo['tmp_name'], cms_join_path($gCms->config['uploads_path'],$curdir,$fileinfo['name'])) )
	$this->Redirect($id, 'browse', $returnid, array('curdir'=>$curdir, 'browse'=>$browsefiles,'error'=>$this->lang('error_unabletomovefile').cms_join_path($gCms->config['uploads_path'],$curdir,$fileinfo['name'])));

if ($params['convert']!='yes')
	$this->Redirect($id, 'browse', $returnid, array('curdir'=>$curdir, 'browse'=>$browsefiles));
else
{
	$params['file'] = $fileinfo['name'];
	require_once(dirname(__FILE__).'/action.convertfile.php');
}

?>