Exemplo n.º 1
0
 function newMediaObject($uid, $username, $password, $mediaobject = array())
 {
     global $_SGLOBAL, $space;
     $fileext = fileext($mediaobject['name']);
     if (!in_array($fileext, array('jpg', 'gif', 'png'))) {
         $this->sendFault(500, 'You should choose image file to upload.');
     }
     $this->authUser($username, $password);
     include_once S_ROOT . './source/function_cp.php';
     $struct = array();
     if ($stream_save = stream_save(sstripslashes($mediaobject['bits']), '0', $fileext)) {
         $struct['url'] = pic_get($stream_save['filepath'], $stream_save['thumb'], $stream_save['remote'], 0);
     } else {
         $this->sendFault(500, 'Sorry, your image could not be uploaded. Something wrong happened.');
     }
     if (!preg_match("/^(http\\:\\/\\/|\\/)/i", $struct['url'])) {
         $struct['url'] = $this->siteUrl . $struct['url'];
     }
     return $struct;
 }
Exemplo n.º 2
0
 function onPhotoUpdate($uId, $pId, $aId, $fileName = null, $fileType = null, $fileSize = null, $caption = null, $data = null)
 {
     global $_G;
     $res = $this->getUserSpace($uId);
     if ($fileName !== null) {
         $fields['filename'] = $fileName;
     }
     if (is_string($caption) && strlen($caption) > 0) {
         $fields['title'] = $caption;
     }
     if (is_string($data) && strlen($data) > 0) {
         $query = DB::query('SELECT size, title, filename FROM ' . DB::table('home_pic') . ' WHERE picid=' . $pId . ' AND albumid=' . $aId . ' AND uid=' . $uId);
         $picInfo = DB::fetch($query);
         if ($picInfo && is_array($picInfo)) {
             require_once libfile('function/spacecp');
             $attachDir = $_SC['attachdir'];
             $_SC['attachdir'] = DISCUZ_ROOT . './' . $_G['setting']['attachdir'];
             $title = $fields['title'] ? $caption : $picInfo['title'];
             $name = $fields['filename'] ? $fileName : $picInfo['filename'];
             $stream = base64_decode($data);
             $pic = stream_save($stream, $aId, $fileType, $name, $title, $picInfo['size']);
             $_SC['attachdir'] = $attachDir;
             $newPic = array();
             if ($pic && is_array($pic)) {
                 require_once libfile('function/delete');
                 deletepics(array($pId));
                 DB::update('home_pic', array('picid' => $pId), array('picid' => $pic['picid']));
                 $newPic['pId'] = $pId;
                 $newPic['src'] = $pic['filepat'];
                 return new APIResponse($newPic);
             } else {
                 if ($res == -1) {
                     $errCode = 122;
                     $errMessage = 'No Enough Space';
                 } else {
                     if ($res == -2) {
                         $errCode = 123;
                         $errMessage = 'Uploaded File Is Not A Valid Image';
                     } else {
                         $errCode = 1;
                         $errMessage = 'Unknown Error';
                     }
                 }
             }
         } else {
             $errCode = 121;
             $errMessage = 'Invalid Picture Id';
         }
         return new ErrorResponse($errCode, $errMessage);
     } else {
         $where = array('uid' => $uId, 'albumid' => $aId, 'picid' => $pId);
         DB::update('home_pic', $fields, $where);
         $query = DB::query('SELECT * FROM ' . DB::table('home_pic') . ' WHERE picid=' . $pId . ' AND uid=' . $uId . ' AND albumid=' . $aId);
         $picInfo = DB::fetch($query);
         if ($picInfo && is_array($picInfo)) {
             $newPic['pId'] = $pId;
             $newPic['src'] = pic_get($picInfo['filepath'], $picInfo['thumb'], $picInfo['remote'], 0);
             if (!preg_match("/^(http\\:\\/\\/|\\/)/i", $newPic['src'])) {
                 $newPic['src'] = $this->_getUchomeUrl() . $newPic['src'];
             }
             return $newPic;
         } else {
             $errCode = 121;
             $errMessage = 'Invalid Picture Id';
             return new ErrorResponse($errCode, $errMessage);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * 更新一张照片
  * @param integer $uId 用户Id
  * @param integer $aId 相册Id
  * @param string  $fileName 文件名
  * @param string  $fileType 文件类型
  * @param integer $fileSize 文件大小
  * @param string  $caption 照片说明
  * @param string  $data 照片数据
  */
 function update($uId, $pId, $aId, $fileName = null, $fileType = null, $fileSize = null, $caption = null, $data = null)
 {
     global $_SGLOBAL;
     if ($fileName !== null) {
         $fields['filename'] = $fileName;
     }
     if (is_string($caption) && strlen($caption) > 0) {
         $fields['title'] = $caption;
     }
     if (is_string($data) && strlen($data) > 0) {
         // 重新上传新图片
         $query = $_SGLOBAL['db']->query('SELECT size, title, filename FROM ' . tname('pic') . ' WHERE picid=' . $pId . ' AND albumid=' . $aId . ' AND uid=' . $uId);
         $picInfo = $_SGLOBAL['db']->fetch_array($query);
         if ($picInfo && is_array($picInfo)) {
             include_once S_ROOT . './source/function_cp.php';
             global $_SC;
             $attachDir = $_SC['attachdir'];
             $_SC['attachdir'] = S_ROOT . './' . $_SC['attachdir'];
             $title = $fields['title'] ? $caption : $picInfo['title'];
             $name = $fields['filename'] ? $fileName : $picInfo['filename'];
             $stream = base64_decode($data);
             $pic = stream_save($stream, $aId, $fileType, $name, $title, $picInfo['size']);
             $_SC['attachdir'] = $attachDir;
             // 返回值跟文档不太一样
             $newPic = array();
             if ($pic && is_array($pic)) {
                 include_once S_ROOT . './source/function_delete.php';
                 deletepics(array($pId));
                 updatetable('pic', array('picid' => $pId), array('picid' => $pic['picid']));
                 $newPic['pId'] = $pId;
                 $newPic['src'] = $pic['filepathall'];
                 return new APIResponse($newPic);
             } else {
                 if ($res == -1) {
                     $errCode = 122;
                     $errMessage = 'No Enough Space';
                 } else {
                     if ($res == -2) {
                         $errCode = 123;
                         $errMessage = 'Uploaded File Is Not A Valid Image';
                     } else {
                         $errCode = 1;
                         $errMessage = 'Unknown Error';
                     }
                 }
             }
         } else {
             $errCode = 121;
             $errMessage = 'Invalid Picture Id';
         }
         return new APIErrorResponse($errCode, $errMessage);
     } else {
         $where = array('uid' => $uId, 'albumid' => $aId, 'picid' => $pId);
         updatetable('pic', $fields, $where);
         $query = $_SGLOBAL['db']->query('SELECT * FROM ' . tname('pic') . ' WHERE picid=' . $pId . ' AND uid=' . $uId . ' AND albumid=' . $aId);
         $picInfo = $_SGLOBAL['db']->fetch_array($query);
         if ($picInfo && is_array($picInfo)) {
             $newPic['pId'] = $pId;
             $newPic['src'] = pic_get($picInfo['filepath'], $picInfo['thumb'], $picInfo['remote'], 0);
             if (!preg_match("/^(http\\:\\/\\/|\\/)/i", $newPic['src'])) {
                 $newPic['src'] = $this->_getUchomeUrl() . $newPic['src'];
             }
             return new APIResponse($newPic);
         } else {
             $errCode = 121;
             $errMessage = 'Invalid Picture Id';
             return new APIErrorResponse($errCode, $errMessage);
         }
     }
 }
Exemplo n.º 4
0
         $uploadfiles = -8;
         $dosave = false;
     }
 }
 //如果为空则代表发送过来的流有错误
 if ($dosave && !empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
     $_SERVER['HTTP_ALBUMID'] = addslashes(siconv(urldecode($_SERVER['HTTP_ALBUMID']), $_SC['charset'], "UTF-8"));
     $from = false;
     if ($op == 'screen') {
         $from = 'camera';
     } elseif ($_GET['from'] == 'album') {
         $from = 'uploadimage';
     }
     $_SCONFIG['allowwatermark'] = 0;
     //禁止添加水印
     $uploadfiles = stream_save($GLOBALS['HTTP_RAW_POST_DATA'], $_SERVER['HTTP_ALBUMID'], 'jpg', '', '', 0, $from);
 }
 $uploadResponse = true;
 $picid = $proid = $albumid = 0;
 if ($uploadfiles && is_array($uploadfiles)) {
     $status = "success";
     $albumid = $uploadfiles['albumid'];
     $picid = $uploadfiles['picid'];
     if ($op == "doodle") {
         $fileurl = pic_get($uploadfiles['filepath'], $uploadfiles['thumb'], $uploadfiles['remote'], 0);
         include_once S_ROOT . './source/function_magic.php';
         magic_use('doodle', array(), 1);
     }
 } else {
     switch ($uploadfiles) {
         case -1:
Exemplo n.º 5
0
        $max = intval($max) * 1024;
    } elseif ($unit == 'm') {
        $max = intval($max) * 1024 * 1024;
    } elseif ($unit == 'g') {
        $max = intval($max) * 1024 * 1024 * 1024;
    }
    $albums = getalbums($_SGLOBAL['supe_uid']);
} elseif ($op == "screen") {
    if (empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
        $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input");
    }
    $uploadfiles = $status = "failure";
    //如果为空则代表发送过来的流有错误
    if (!empty($GLOBALS['HTTP_RAW_POST_DATA'])) {
        $_SERVER['HTTP_ALBUMID'] = addslashes(siconv(urldecode($_SERVER['HTTP_ALBUMID']), $_SC['charset'], "UTF-8"));
        $uploadfilesarr = stream_save($GLOBALS['HTTP_RAW_POST_DATA'], $_SERVER['HTTP_ALBUMID'], 'jpg');
    }
    $uploadResponse = true;
    $proid = $albumid = 0;
    if ($uploadfilesarr && is_array($uploadfilesarr)) {
        $uploadfiles = $status = "success";
        $albumid = $uploadfilesarr['albumid'];
    }
} elseif ($_FILES && $_POST) {
    if ($_FILES["Filedata"]['error']) {
        $uploadfiles = cplang('file_is_too_big');
    } else {
        $_FILES["Filedata"]['name'] = addslashes(siconv(urldecode($_FILES["Filedata"]['name']), $_SC['charset'], "UTF-8"));
        $_POST['albumid'] = addslashes(siconv(urldecode($_POST['albumid']), $_SC['charset'], "UTF-8"));
        $uploadfiles = pic_save($_FILES["Filedata"], $_POST['albumid'], addslashes(siconv(urldecode($_POST['title']), $_SC['charset'], "UTF-8")));
    }