Ejemplo n.º 1
0
function markdown_upload_ajax_image()
{
    global $zbp;
    $xhr = array('error' => "", 'url' => "");
    foreach ($_FILES as $key => $value) {
        if ($_FILES[$key]['error'] == 0) {
            if (is_uploaded_file($_FILES[$key]['tmp_name'])) {
                $tmp_name = $_FILES[$key]['tmp_name'];
                $name = $_FILES[$key]['name'];
                $upload = new Upload();
                $upload->Name = $_FILES[$key]['name'];
                $upload->SourceName = $_FILES[$key]['name'];
                $upload->MimeType = $_FILES[$key]['type'];
                $upload->Size = $_FILES[$key]['size'];
                $upload->AuthorID = $zbp->user->ID;
                if (!$upload->CheckExtName()) {
                    $xhr['error'] = $this->lang['error'][26];
                }
                if (!$upload->CheckSize()) {
                    $xhr['error'] = $this->lang['error'][27];
                }
                $upload->SaveFile($_FILES[$key]['tmp_name']);
                $upload->Save();
            }
        }
    }
    if (isset($upload)) {
        CountMemberArray(array($upload->AuthorID), array(0, 0, 0, +1));
        $xhr['url'] = $upload->Url;
    }
    echo json_encode($xhr);
}
Ejemplo n.º 2
0
function PostUpload()
{
    global $zbp;
    foreach ($_FILES as $key => $value) {
        if ($_FILES[$key]['error'] == 0) {
            if (is_uploaded_file($_FILES[$key]['tmp_name'])) {
                $tmp_name = $_FILES[$key]['tmp_name'];
                $name = $_FILES[$key]['name'];
                $upload = new Upload();
                $upload->Name = $_FILES[$key]['name'];
                $upload->SourceName = $_FILES[$key]['name'];
                $upload->MimeType = $_FILES[$key]['type'];
                $upload->Size = $_FILES[$key]['size'];
                $upload->AuthorID = $zbp->user->ID;
                if (!$upload->CheckExtName()) {
                    $zbp->ShowError(26);
                }
                if (!$upload->CheckSize()) {
                    $zbp->ShowError(27);
                }
                $upload->SaveFile($_FILES[$key]['tmp_name']);
                $upload->Save();
            }
        }
    }
    if (isset($upload)) {
        CountMemberArray(array($upload->AuthorID));
    }
}
Ejemplo n.º 3
0
    // if (empty($ext_arr[$dir_name])) {
    // 	alert("目录名不正确。");
    // }
    //获得文件扩展名
    $temp_arr = explode(".", $file_name);
    $file_ext = array_pop($temp_arr);
    $file_ext = trim($file_ext);
    $file_ext = strtolower($file_ext);
    //检查扩展名
    if (in_array($file_ext, $ext_arr) === false) {
        alert("上传文件扩展名是不允许的扩展名。\n只允许" . implode(",", $ext_arr) . "格式。");
    }
    $upload = new Upload();
    $upload->Name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
    $upload->SourceName = $file_name;
    $upload->MimeType = $_FILES['imgFile']['type'];
    $upload->Size = $file_size;
    $upload->AuthorID = $zbp->user->ID;
    $upload->SaveFile($tmp_name);
    $upload->Save();
    $file_url = $upload->Url;
    header('Content-type: text/html; charset=UTF-8');
    echo json_encode(array('error' => 0, 'url' => $file_url));
    exit;
}
function alert($msg)
{
    header('Content-type: text/html; charset=UTF-8');
    echo json_encode(array('error' => 1, 'message' => $msg));
    exit;
}
Ejemplo n.º 4
0
function zbp_newMediaObject($xmlstring)
{
    global $zbp;
    $xml = simplexml_load_string($xmlstring);
    if ($xml) {
        $post = array();
        foreach ($xml->children() as $x) {
            $a = (string) $x->name;
            $b = $x->value->children();
            $post[$a] = $b;
        }
        $upload = new Upload();
        $f = GetGuid() . strrchr($post['name'], '.');
        $upload->Name = $f;
        $upload->SourceName = $post['name'];
        $upload->MimeType = $post['type'];
        $upload->Size = 0;
        $upload->AuthorID = $zbp->user->ID;
        $upload->SaveBase64File($post['bits']);
        $upload->Save();
        $strXML = '<methodResponse><params><param><value><struct><member><name>url</name><value><string>$%#1#%$</string></value></member></struct></value></param></params></methodResponse>';
        $strXML = str_replace("\$%#1#%\$", htmlspecialchars($upload->Url), $strXML);
        echo $strXML;
    }
}
Ejemplo n.º 5
0
 /**
  * 拉取远程图片
  * @return mixed
  */
 private function saveRemote()
 {
     global $zbp;
     $imgUrl = htmlspecialchars($this->fileField);
     $imgUrl = str_replace("&amp;", "&", $imgUrl);
     //http开头验证
     if (strpos($imgUrl, "http") !== 0) {
         $this->stateInfo = $this->getStateInfo("ERROR_HTTP_LINK");
         return;
     }
     //获取请求头并检测死链
     $heads = get_headers($imgUrl, 1);
     if (!(stristr($heads[0], "200") && stristr($heads[0], "OK"))) {
         $this->stateInfo = $this->getStateInfo("ERROR_DEAD_LINK");
         return;
     }
     //格式验证(扩展名验证和Content-Type验证)
     $fileType = strtolower(strrchr($imgUrl, '.'));
     if (!in_array($fileType, $this->config['allowFiles']) || !stristr($heads['Content-Type'], "image")) {
         $this->stateInfo = $this->getStateInfo("ERROR_HTTP_CONTENTTYPE");
         return;
     }
     //打开输出缓冲区并获取远程图片
     ob_start();
     $context = stream_context_create(array('http' => array('follow_location' => false)));
     readfile($imgUrl, false, $context);
     $img = ob_get_contents();
     ob_end_clean();
     preg_match("/[\\/]([^\\/]*)[\\.]?[^\\.\\/]*\$/", $imgUrl, $m);
     $this->oriName = $m ? $m[1] : "";
     $this->fileSize = strlen($img);
     $this->fileType = $this->getFileExt();
     $this->fullName = $this->getFullName();
     $this->filePath = $this->getFilePath();
     $this->fileName = $this->getFileName();
     $dirname = dirname($this->filePath);
     //检查文件大小是否超出限制
     if (!$this->checkSize()) {
         $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
         return;
     }
     $upload = new Upload();
     $upload->Name = $this->fileName;
     $upload->SourceName = $this->fileName;
     $upload->MimeType = $heads['Content-Type'];
     $upload->Size = $this->fileSize;
     $upload->AuthorID = $zbp->user->ID;
     if (!$upload->SaveBase64File(base64_encode($img))) {
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
         return;
     }
     $upload->Save();
     $this->fullName = $upload->Url;
 }
Ejemplo n.º 6
0
/**
 * 附件上传
 */
function PostUpload()
{
    global $zbp;
    foreach ($_FILES as $key => $value) {
        if ($_FILES[$key]['error'] == 0) {
            if (is_uploaded_file($_FILES[$key]['tmp_name'])) {
                $upload = new Upload();
                $upload->Name = $_FILES[$key]['name'];
                if (GetVars('auto_rename', 'POST') == 'on' || GetVars('auto_rename', 'POST') == true) {
                    $temp_arr = explode(".", $upload->Name);
                    $file_ext = strtolower(trim(array_pop($temp_arr)));
                    $upload->Name = date("YmdHis") . time() . rand(10000, 99999) . '.' . $file_ext;
                }
                $upload->SourceName = $_FILES[$key]['name'];
                $upload->MimeType = $_FILES[$key]['type'];
                $upload->Size = $_FILES[$key]['size'];
                $upload->AuthorID = $zbp->user->ID;
                //检查同月重名
                $d1 = date('Y-m-01', time());
                $d2 = date('Y-m-d', strtotime(date('Y-m-01', time()) . ' +1 month -1 day'));
                $d1 = strtotime($d1);
                $d2 = strtotime($d2);
                $w = array();
                $w[] = array('=', 'ul_Name', $upload->Name);
                $w[] = array('>=', 'ul_PostTime', $d1);
                $w[] = array('<=', 'ul_PostTime', $d2);
                $uploads = $zbp->GetUploadList('*', $w);
                if (count($uploads) > 0) {
                    $zbp->ShowError(28, __FILE__, __LINE__);
                }
                if (!$upload->CheckExtName()) {
                    $zbp->ShowError(26, __FILE__, __LINE__);
                }
                if (!$upload->CheckSize()) {
                    $zbp->ShowError(27, __FILE__, __LINE__);
                }
                $upload->SaveFile($_FILES[$key]['tmp_name']);
                $upload->Save();
            }
        }
    }
    if (isset($upload)) {
        CountMemberArray(array($upload->AuthorID), array(0, 0, 0, +1));
    }
}