嗯嗯
- 嗯嗯 回答了问题 有没有人知道基于YII2的在线课程系统
慕课网有。。。。。。。。
- 嗯嗯 回答了问题 arrayHelper数组助手配置语言包
1111111111111111111111
- 嗯嗯 回答了问题 yii1 如何记录所有方法的请求记录及输出记录
写日志111111111111
/**
* * @param string|array $uploadedFile 输入框名称 或者 [model,attribute] * @param type $directory * @return JsonResponse * @throws ApiException */ public function uploadOne($uploadedFile, $directory = '') { try { if ($directory) { $this->uploadDir .= DIRECTORY_SEPARATOR . $directory; } if (is_string($uploadedFile)) { $upload = UploadedFile::getInstanceByName($uploadedFile); $name = $uploadedFile; } else if (is_array($uploadedFile) && isset($uploadedFile['model']) && isset($uploadedFile['attribute'])) { $upload = UploadedFile::getInstance($uploadedFile['model'], $uploadedFile['attribute']); $name = $uploadedFile['attribute']; } if ($upload !== null) { $this->saveName .= '.' . $upload->getExtension(); if (!in_array($upload->getExtension(), $this->pictureConfig['allowType'])) { throw new ApiException(JsonResponseMsg::TYPE_NOT_ALLOWED, JsonResponseCode::TYPE_NOT_ALLOWED); } $originalPath = $this->uploadDir . DIRECTORY_SEPARATOR . $this->pictureConfig['originalDir'] . DIRECTORY_SEPARATOR . $this->savePath . DIRECTORY_SEPARATOR; $file = $this->apiWebPath . $originalPath . $this->saveName; $this->createDir($this->apiWebPath . $originalPath); if ($upload->saveAs($file) && $this->water($file) && $this->text($file) && $this->thumb($file)) { JsonResponse::success()->pushData($name, ['savePath' => $originalPath, 'saveName' => $this->saveName, 'file' => $originalPath . $this->saveName]); } else { if ($upload->getHasError()) { $code = $upload->error; switch ($code) { case UPLOAD_ERR_INI_SIZE: $message = "The uploaded file exceeds the upload_max_filesize directive in php.ini"; break; case UPLOAD_ERR_FORM_SIZE: $message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"; break; case UPLOAD_ERR_PARTIAL: $message = "The uploaded file was only partially uploaded"; break; case UPLOAD_ERR_NO_FILE: $message = "No file was uploaded"; break; case UPLOAD_ERR_NO_TMP_DIR: $message = "Missing a temporary folder"; break; case UPLOAD_ERR_CANT_WRITE: $message = "Failed to write file to disk"; break; case UPLOAD_ERR_EXTENSION: $message = "File upload stopped by extension"; break; default: $message = "Unknown upload error"; break; } JsonResponse::setMessage($message); JsonResponse::setCode(JsonResponseCode::PICTURE_UPLOAD_FAILED); } @unlink($file); } } else { $message = "No file was uploaded"; JsonResponse::setMessage($message); } } catch (\Exception $ex) { if ($ex instanceof ApiException) { $code = $ex->getCode(); } else { $code = JsonResponseCode::FAIL; } JsonResponse::fail($code, $ex->getMessage()); } return JsonResponse::getInstance(); } public function thumb($filename) { if ($this->pictureConfig['thumb'] === false) { return true; } $thumbDir = $this->pictureConfig['thumbDir']; $savePath = $this->uploadDir . DIRECTORY_SEPARATOR . $thumbDir . DIRECTORY_SEPARATOR . $this->savePath . DIRECTORY_SEPARATOR; $saveName = basename($filename); $this->createDir($this->apiWebPath . $savePath); $this->setImagesize($filename); if ($this->imagesize) { $width = round($this->imagesize[0] / $this->pictureConfig['minification']); $height = round($this->imagesize[1] / $this->pictureConfig['minification']); $this->checkImgSize($filename); //Image::thumbnail($filename, $width, $height)->save($this->apiWebPath . $savePath . $saveName); JsonResponse::pushData('thumb', ['savePath' => $savePath, 'saveName' => $saveName]); return true; } return false; } private function checkImgSize($filename) { $this->setImagesize($filename); if ($this->imagesize[0] > 3000 || $this->imagesize[1] > 3000) { throw new ApiException(JsonResponseMsg::PICTURE_SIZE_TOO_BIG, JsonResponseCode::PICTURE_UPLOAD_FAILED); } } private function water($filename) { try { if ($this->pictureConfig['water'] === false) { return true; } $this->checkImgSize($filename); $waterPosition = $this->pictureConfig['waterPosition']; $waterPicture = $this->pictureConfig['waterPicture']; if (!$waterPosition) { $imagesize = @getimagesize($waterPicture); $this->setImagesize($filename); $waterPosition = [mt_rand(0, abs($this->imagesize[0] - $imagesize[0])), mt_rand(0, abs($this->imagesize[1] - $imagesize[1]))]; } Image::watermark($filename, $waterPicture, $waterPosition)->save(); return true; } catch (\Exception $ex) { } return false; } public function text($filename) { try { if ($this->pictureConfig['text'] === false) { return true; } $this->checkImgSize($filename); $textPosition = $this->pictureConfig['textPosition']; if (!$textPosition) { $textPosition = [0, 0]; } Image::text($filename, $this->pictureConfig['waterText'], $this->pictureConfig['waterFont'], $textPosition, ['color' => $this->pictureConfig['textColor'], 'size' => $this->pictureConfig['textSize']])->save(); return true; } catch (\Exception $ex) { } return false; } private function createDir($dir) { if (!file_exists($dir) || !is_dir($dir)) { mkdir($dir, 0777, true); } } private function setImagesize($filename) { $this->imagesize === null && $this->imagesize = @getimagesize($filename); }
...............
- 嗯嗯 2017-08-24 已签到连续签到4天,获得了20个金钱
- 嗯嗯 2017-08-23 已签到连续签到3天,获得了15个金钱