private function _deleteTempAvatarFiles($uid)
 {
     $files = $this->_getTempAvatarFiles($uid);
     $path = UploadUtils::getTempAvatarPath();
     foreach ($files as $fileName) {
         FileUtils::safeDeleteFile($path . '/' . $fileName);
     }
 }
 private function _runAction($res, $uid)
 {
     ($imageData = file_get_contents('php://input')) === false && ($imageData = $GLOBALS['HTTP_RAW_POST_DATA']);
     //$imageData = file_get_contents('http://appbyme.com/mobcentACA/resource/images/logo.jpg');
     if (!empty($imageData)) {
         if (($savePath = UploadUtils::getTempAvatarPath()) != '') {
             $fileName = sprintf('%s/avatar_%s.jpg', $savePath, $uid);
             if (($pfile = fopen($fileName, 'wb')) != false) {
                 if (fwrite($pfile, $imageData) !== false) {
                     $image = $this->_uploadAvatarByUcenter($uid, $fileName, $imageData);
                 }
                 fclose($pfile);
                 FileUtils::safeDeleteFile($fileName);
                 if (!empty($image)) {
                     return array_merge($res, array('icon_url' => '', 'pic_path' => $image));
                 }
             }
         }
     }
     return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件失败'));
 }
示例#3
0
 private function _doUpload($res, $type)
 {
     $config = WebUtils::getMobcentConfig('misc');
     $path = $config['apnsCertfilePath'];
     $certfileAPNs = $path . '/' . $config['apnsCertfileName'];
     if ($type == 'add_certfile_apns') {
         $password = (string) $_POST['passphrase'];
         if (UploadUtils::makeBasePath($path)) {
             if (!empty($_FILES) && count($_FILES) && is_uploaded_file($_FILES['file']['tmp_name']) && !$_FILES['file']['error']) {
                 FileUtils::saveFile($certfileAPNs, file_get_contents($_FILES['file']['tmp_name']));
                 AppbymeConfig::setAPNsCertfilePassword($password);
             } else {
                 $res = $this->makeErrorInfo($res, WebUtils::t('上传失败'));
             }
         }
     } else {
         if ($type == 'del_certfile_apns') {
             FileUtils::safeDeleteFile($certfileAPNs);
         }
     }
     return $res;
 }
示例#4
0
 public static function getThumbImageEx($image, $timeout = 15, $getImageInfo = false, $inBackgroud = false, $force = false)
 {
     $res = array('image' => $image, 'ratio' => '1');
     if (empty($image)) {
         return $res;
     }
     $config = self::_getThumbConfig();
     $allowDiscuzThumb = WebUtils::getDzPluginAppbymeAppConfig('image_thumb_allow_discuz');
     if (!$force && !$config['isThumb'] && $allowDiscuzThumb < 0) {
         return $res;
     }
     $thumbImage = $image;
     global $_G;
     $attachFile = '';
     // 是否用discuz生成的缩略图
     if ($allowDiscuzThumb === false || $allowDiscuzThumb > 0) {
         if ($_G['setting']['ftp']['on'] == 0) {
             $attachUrl = self::getAttachUrl();
             $attachUrl = str_replace($attachUrl, '', $image);
             $attachFile = $_G['setting']['attachdir'] . $attachUrl;
             $attachThumbFile = $attachFile . self::DISCUZ_THUMB_SUFFIX;
             if (file_exists($attachThumbFile)) {
                 $res['image'] = $thumbImage . self::DISCUZ_THUMB_SUFFIX;
                 if ($getImageInfo) {
                     $imageInfo = ImageUtils::getImageInfo($attachThumbFile);
                     $res['ratio'] = $imageInfo['ratio'];
                 }
                 return $res;
             }
         }
     }
     if (!$force && !$config['isThumb']) {
         return $res;
     }
     // 获取缩略图文件名
     $savePath = sprintf('%s/%s', MOBCENT_THUMB_PATH, self::_getThumbTempPath($image));
     $tempFileName = self::_getThumbTempFile($image);
     $smallFileName = $savePath . '/mobcentSmallPreview_' . $tempFileName;
     $bigFileName = $savePath . '/mobcentBigPreview_' . $tempFileName;
     if (file_exists($smallFileName) && file_exists($bigFileName)) {
         $res['image'] = self::_getThumbUrlFile($image, $tempFileName);
         if ($getImageInfo) {
             $imageInfo = ImageUtils::getImageInfo($smallFileName);
             $res['ratio'] = $imageInfo['ratio'];
         }
         return $res;
     }
     if ($inBackgroud) {
         CacheUtils::addThumbTaskList($image);
         return $res;
     }
     if (!is_dir($savePath)) {
         mkdir($savePath, 0777, true);
     }
     if (is_writable($savePath)) {
         // $timer = new CountTimer;
         // 先查看是否是本地附件的图片, 如果不是才去网络取图片数据
         $imageData = '';
         if ($attachFile != '' && file_exists($attachFile)) {
             $imageData = file_get_contents($attachFile);
         }
         if ($imageData == '') {
             $imageData = WebUtils::httpRequest($image, $timeout);
             if ($imageData == '') {
                 return $res;
             }
         }
         $thumb = null;
         $zoomRes = true;
         require_once MOBCENT_APP_ROOT . '/components/discuz/source/class/class_image.php';
         if (!file_exists($smallFileName)) {
             if (file_put_contents($smallFileName, $imageData) == false) {
                 return $res;
             }
             $thumb = new Mobcent_Image();
             $zoomRes &= $thumb->makeThumb($smallFileName, '', $config['imageSmallLength']);
         }
         if (!file_exists($bigFileName)) {
             if (file_put_contents($bigFileName, $imageData) == false) {
                 return $res;
             }
             $thumb == null && ($thumb = new Mobcent_Image());
             $zoomRes &= $thumb->makeThumb($bigFileName, '', $config['imageBigLength']);
         }
         if (file_exists($smallFileName) && file_exists($bigFileName) && $zoomRes) {
             $thumbImage = self::_getThumbUrlFile($image, $tempFileName);
             if ($getImageInfo) {
                 $imageInfo = ImageUtils::getImageInfo($smallFileName);
                 $res['ratio'] = $imageInfo['ratio'];
             }
         } else {
             FileUtils::safeDeleteFile($smallFileName);
             FileUtils::safeDeleteFile($bigFileName);
         }
         // var_dump($timer->stop());
     }
     $res['image'] = $thumbImage;
     return $res;
 }
 private function _runAction($res, $uid)
 {
     if (empty($_FILES['userAvatar']['tmp_name'])) {
         return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('请选择上传的文件'));
     }
     if ($_FILES['userAvatar']['error'] > 0) {
         return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件失败'));
     }
     if ($_FILES['userAvatar']['size'] > 2000000) {
         return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件太大'));
     }
     $savePath = UploadUtils::getTempAvatarPath();
     $fileName = sprintf('%s/avatar_%s.jpg', $savePath, $uid);
     if (move_uploaded_file($_FILES['userAvatar']['tmp_name'], $fileName)) {
         $imageData = file_get_contents($fileName);
         $image = $this->_uploadAvatarByUcenter($uid, $fileName, $imageData);
         FileUtils::safeDeleteFile($fileName);
         if (!empty($image)) {
             return array_merge($res, array('icon_url' => '', 'pic_path' => $image));
         }
         // WebUtils::httpRequestAppAPI('user/saveavatar', array('avatar' => $image, 'hacker_uid' => 1));
         // die();
     }
     return WebUtils::makeErrorInfo_oldVersion($res, WebUtils::t('上传文件失败'));
 }