Beispiel #1
0
 /**
  * mwNewMediaObject
  *
  * @param int $blogId
  * @param string $userName
  * @param string $password
  * @param mixed $data
  * @access public
  * @return void
  */
 public function mwNewMediaObject($blogId, $userName, $password, $data)
 {
     if (!$this->checkAccess($userName, $password)) {
         return $this->error;
     }
     $result = Widget_Upload::uploadHandle($data);
     if (false === $result) {
         return IXR_Error(500, _t('上传失败'));
     } else {
         $insertId = $this->insert(array('title' => $result['name'], 'slug' => $result['name'], 'type' => 'attachment', 'status' => 'publish', 'text' => serialize($result), 'allowComment' => 1, 'allowPing' => 0, 'allowFeed' => 1));
         $this->db->fetchRow($this->select()->where('table.contents.cid = ?', $insertId)->where('table.contents.type = ?', 'attachment'), array($this, 'push'));
         /** 增加插件接口 */
         $this->pluginHandle()->upload($this);
         return array('file' => $this->attachment->name, 'url' => $this->attachment->url);
     }
 }
Beispiel #2
0
<?php

header('Content-Type: text/html; charset=UTF-8');
$rootDir = strstr(dirname(__FILE__), 'usr', TRUE);
require_once $rootDir . 'config.inc.php';
require_once $rootDir . 'var/Typecho/Common.php';
require_once $rootDir . 'var/Typecho/Request.php';
require_once $rootDir . 'var/Widget/Upload.php';
$fileInfo = Widget_Upload::uploadHandle($_FILES['upload']);
if (false === $fileInfo) {
    echo '上传失败!';
} else {
    echo sprintf("<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction(1, '%s', '');</script>", Typecho_Request::getInstance()->getUrlPrefix() . $fileInfo['path']);
}