示例#1
0
文件: add.php 项目: ahmatjan/manage
    public function jointHtml()
    {
        $html = array();
        $html[] = '<!DOCTYPE HTML><html>';
        $html[] = implode(" ", $this->head);
        $html[] = implode(" ", $this->body);
        $html[] = '</html>';
        return implode(" ", $html);
    }
}
//addslashes 转义函数
if (isset($_POST['action']) && $_POST['action'] == 'toModuleSave' && isset($_POST['htmlCode']) && isset($_POST['cssCode'])) {
    $moduleName = $_POST['title'];
    $db = new DB();
    $File = new FileUtil();
    $File->createDir(BASE_PATH . 'upload/webstyle/module/' . date('Y-m-d-H-i-s') . '/css/');
    $cssFilePath = '/upload/webstyle/module/' . date('Y-m-d-H-i-s') . '/css/index.css';
    $File->writetofile(BASE_PATH . $cssFilePath, $_POST['cssCode']);
    $cssCodeId = $db->insert('webstyle_code', insertCode($moduleName . '_css', addslashes($_POST['cssCode']), 'css', '/manage' . $cssFilePath), true);
    if (isset($_POST['jsCode'])) {
        $File->createDir(BASE_PATH . 'upload/webstyle/module/' . date('Y-m-d-H-i-s') . '/js/');
        $jsFilePath = '/upload/webstyle/module/' . date('Y-m-d-H-i-s') . '/js/index.js';
        $File->writetofile(BASE_PATH . $jsFilePath, $_POST['jsCode']);
        $jsCodeId = $db->insert('webstyle_code', insertCode($moduleName . '_js', addslashes($_POST['jsCode']), 'js', '/manage' . $jsFilePath), true);
    }
    $File->createDir(BASE_PATH . 'upload/webstyle/module/' . date('Y-m-d-H-i-s'));
    $htmlFilePath = '/upload/webstyle/module/' . date('Y-m-d-H-i-s') . '/index.html';
    $jointHtml = new JointHtml($_POST['htmlCode'], 'css/index.css', 'js/index.js');
    $htmlCode = $jointHtml->jointHtml();
    $File->writetofile(BASE_PATH . $htmlFilePath, $htmlCode);
    $htmlCodeId = $db->insert('webstyle_code', insertCode($moduleName . '_html', addslashes($_POST['htmlCode']), 'html', '/manage' . $htmlFilePath), true);
示例#2
0
        case 6:
            // 文件写入到临时文件夹出错
            $result = json_encode(array('code' => 6, 'message' => "文件写入到临时文件夹出错"));
            break;
        case 7:
            // 文件写入失败
            $result = json_encode(array('code' => 6, 'message' => "文件写入失败"));
            break;
        default:
            // 文件保存失败
            $result = json_encode(array('code' => 9, 'message' => "文件保存失败"));
            break;
    }
    echo $result;
} else {
    if ($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/jpg" || $_FILES["file"]["type"] == "image/png" || $_FILES["file"]["type"] == "image/bmp" || $_FILES["file"]["type"] == "image/pjpeg") {
        $folder = "images/";
    } else {
        $folder = "files/";
    }
    $fu = new FileUtil();
    $fu->createDir($folder . $dir);
    move_uploaded_file($_FILES["file"]["tmp_name"], $folder . $dir . $filename);
    $result = json_encode(array('code' => 0, 'message' => $folder . $dir . $filename));
    echo $result;
}
function getMillisecond()
{
    list($s1, $s2) = explode(' ', microtime());
    return (double) sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
示例#3
0
 /**
  * 复制文件
  *
  * @param string $fileUrl
  * @param string $aimUrl
  * @param boolean $overWrite 该参数控制是否覆盖原文件
  * @return boolean
  */
 function copyFile($fileUrl, $aimUrl, $overWrite = false)
 {
     if (!file_exists($fileUrl)) {
         return false;
     }
     if (file_exists($aimUrl) && $overWrite == false) {
         return false;
     } elseif (file_exists($aimUrl) && $overWrite == true) {
         FileUtil::unlinkFile($aimUrl);
     }
     $aimDir = dirname($aimUrl);
     FileUtil::createDir($aimDir);
     copy($fileUrl, $aimUrl);
     return true;
 }
示例#4
0
 /**
  * 复制文件
  *
  * @param string $fileUrl
  * @param string $aimUrl
  * @param boolean $overWrite 该参数控制是否覆盖原文件
  * @param boolean $useBackup 该参数控制是否备份,只在$overWrite为TRUE时生效
  * @param string  $backupUrl 该参数控制备份文件对象,只在$useBackup为TRUE时生效
  * @return boolean
  */
 function copyFile($fileUrl, $aimUrl, $overWrite = false, $useBackup = false, $backupUrl)
 {
     if (!file_exists($fileUrl)) {
         return false;
     }
     if (file_exists($aimUrl) && $overWrite == false) {
         return false;
     } else {
         if (file_exists($aimUrl) && $overWrite == true) {
             if ($useBackup == true && file_exists($backupUrl)) {
                 return false;
             } else {
                 FileUtil::moveFile($aimUrl, $backupUrl);
             }
             FileUtil::unlinkFile($aimUrl);
         }
     }
     $aimDir = dirname($aimUrl);
     FileUtil::createDir($aimDir);
     copy($fileUrl, $aimUrl);
     return true;
 }