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; }
/** * 上传图片 * * @author HanPengyu * @access public * * @return mixed 返回状态码和信息. */ public function actionUploadIcon($type = 'uidiy') { $res = WebUtils::initWebApiResult(); // 没有上传的文件 if (empty($_FILES)) { self::makeResponse(0, '没有上传的文件,或者选择的文件太大!'); } // 创建放置图片的文件夹 $date = date('Ym/d', time()); $path = MOBCENT_UPLOAD_PATH . '/' . $type . '/' . $date; if (UploadUtils::makeBasePath($path) == '') { self::makeResponse(0, '上传目录不可写!'); } foreach ($_FILES as $file) { $file['name'] = strip_tags($file['name']); $ext = FileUtils::getFileExtension($file['name'], 'jpg'); // 检测 $imageRes = $this->checkUpload($res, $file); if (!$imageRes['errCode']) { self::makeResponse(0, $imageRes['errMsg']); } $saveName = FileUtils::getRandomUniqueFileName($path); $fileName = $saveName . '.' . $ext; if (!move_uploaded_file($file['tmp_name'], $fileName)) { self::makeResponse(0, '上传图片失败!'); } $fileName = $this->dzRootUrl . '/data/appbyme/upload/' . $type . '/' . $date . '/' . basename($fileName); ImageUtils::getThumbImageEx($fileName, 10, false, false, true); self::makeResponse(1, $fileName); } }