示例#1
0
    function _default()
    {
        global $dir;
        if (!MRights::can("open")) {
            return $this->_noAuth("open");
        }
        $syntax = MRequest::clean("syntax");
        $uniq = getUnique();
        $height = MRequest::int("height", 550);
        $sid = MRequest::int("sid", null);
        //$content = implode('', file($dir));
        $content = "";
        $encoding = MText::_("nofile");
        if (MFile::is($dir) && MFile::isFile($dir)) {
            $content = MFile::readData($dir);
            $padding = $syntax == "text" ? "0px" : "0px";
            $this->view->content('<form id="saveeditfile" method="post" action="' . MURL::_("xhredit", MURL::safePath($dir), "save", "sid=" . $sid) . '">
				<input type="hidden" name="close" id="is_close" value="0"></input>	
				<input type="hidden" name="syntax" value="' . htmlentities($syntax) . '"></input>	
				<input type="hidden" name="height" value="' . htmlentities($height) . '"></input>	
				<textarea id="mEditArea-' . $sid . '" name="content" style="width:100%; height:' . $height . 'px;margin:-4px;padding:' . $padding . ';">' . htmlentities($content) . '</textarea>
			
				<div class="toRight" style="margin-top:5px;">
				<a href="" class="askButton" style="width:120px; text-align:center;" onclick="javascript: mCodeMirrorSubmit(\'' . $sid . '\'); mFormSubmit(_(\'saveeditfile\'));">' . MText::_("save") . '</a>
				<a href="" class="askButton" style="width:200px; text-align:center;" onclick="javascript: _(\'is_close\').value = 1;  mCodeMirrorSubmit(\'' . $sid . '\'); mFormSubmit(_(\'saveeditfile\'));">' . MText::_("saveandclose") . '</a>
				<a href="" class="askButton" style="width:120px; text-align:center;" onclick="javascript: closePopup(\'Edit' . $sid . '\'); ">' . MText::_("cancel") . '</a>
				</div>
				</form>
				<span style="display:none;" class="mCodeMirrorData" syntax="' . $syntax . '" sid="' . $sid . '" height="' . $height . '"></span>
			');
            //<script language="javascript" type="text/javascript" src="'.MURL::_("xhreditarea",null,null,"syntax=".$syntax."&sid=".$sid."&height=".urlencode($height) ).'" noCache="1"></script>
        } else {
            $this->view->content('<h2 style="color:red">' . $encoding . '</h2>');
        }
    }
示例#2
0
<?php

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = str_replace('//', '/', $_GET['folder'] . '/');
    $targetFile = $_FILES['Filedata']['name'];
    // Create the directory if it doesn't exist
    //mkdir(str_replace('//','/',$targetPath), 0755, true);
    // Make sure the filename is unique
    $targetFile = getUnique($targetFile, $targetPath);
    move_uploaded_file($tempFile, $targetPath . $targetFile);
}
echo $targetFile;
// Check if the file already exists and, if so,
// increments a number at the end until it is unique
function getUnique($fileName, $path)
{
    $baseName = preg_replace('/^(.*)\\.[^.]+$/', '\\1', $fileName);
    $extension = preg_replace('/^.*(\\.[^.]+$)/', '\\1', $fileName);
    $i = 1;
    while (file_exists($path . $fileName)) {
        $fileName = $baseName . '_' . $i . $extension;
        $i++;
    }
    return $fileName;
}