作者 liyuhang

gx

APP_NAME=Laravel
APP_ENV=test
APP_KEY=base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow=
APP_DEBUG=false
APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=globalso
DB_USERNAME=debian-sys-maint
DB_PASSWORD=WtujxV73XIclQet0
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
... ... @@ -2,6 +2,7 @@
namespace App\Http\Controllers\Aside;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Project as ProjectModel;
... ... @@ -20,6 +21,16 @@ class ProjectController extends BaseController
public function lists(){
$projectModel = new ProjectModel();
$lists = $projectModel->lists($this->map,$this->p,$this->row,$this->order);
$this->result($lists);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :添加项目
* @return void
* @author :liyuhang
* @method
*/
public function add(){
$projectModel = new ProjectModel();
}
}
... ...
... ... @@ -4,12 +4,41 @@ namespace App\Http\Controllers;
use App\Enums\Common\Code;
use App\Models\Image as ImageModel;
use Faker\Provider\Image;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
class ImageController
{
public $upload_img = [
//验证
'rule' => [
'size' => 3 * 1024 * 1024, //大小限制
'ext' => 'jpeg,jpg,png,gif', //文件类型限制
],
//生成文件规则
'savename' => 'uniqid',
//设置静态缓存参数(304)
'header' => [
'Cache-Control' => 'max-age=2592000',
'Pragma' => 'cache',
'Expires' => "%Expires%", // cache 1 month
'etag' => "%etag%",
'Last-Modified' => "%Last-Modified%",
'Content-Description' => 'File Transfer',
],
//图片保存根路径
'path' => './uploads/images/',
//图片上传变量名
'name' => 'image',
];
public $request = '';
public function __construct(Request $request)
{
$this->request = $request;
}
public function index($hash = '', $w = 0 ,$h = 0){
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
... ... @@ -21,15 +50,26 @@ class ImageController
if ($info === false) {
$this->response('指定图片不存在!', 404);
}
//查看缩略图是否存在
$filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
if(is_file($filename)){
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
$content = file_get_contents($filename);
$header['Content-Length'] = $info['size'];
return response($content, 200, $header);
}
$path = './../'.$info['path'];
if (!is_file($path)) {
$this->response('指定图片已被系统删除!', 404,$path);
$this->response('指定图片已被系统删除!', 404);
}
$content = '';
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'], [$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->config['header_cache']);
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
if ($w > 0 && $h > 0) {
$path = $this->cacheImage($info, $w, $h, 2);
$path = $this->cacheImage($info, $w, $h);
$content = file_get_contents($path);
$header['Content-Length'] = strlen($content);
} else {
... ... @@ -38,7 +78,51 @@ class ImageController
}
return response($content, 200, $header);
}
/**
* 图片上传
*/
public function upload() {
$files = $this->request->file('image');
if (empty($files)) {
$this->response('没有上传的文件!', 400);
}
$type = $this->request->post('type', 'single');
if ($type == 'multi') {
return $this->multi($files);
} else {
return $this->single($files);
}
}
/**
* @name :上传图片
* @return void
* @author :liyuhang
* @method
*/
public function single($files){
if (is_array($files)) {
$file = current($files);
}
$image = $this->request->file('image');
if(empty($image)){
return $this->fail('没有上传图片',Code::USER_ERROR);
}
$url = './../uploads/images/';
$filename = date('ymdHis').rand(10000,99999);
$res = $this->request->file('image')->move($url,$filename);
if ($res === false) {
return $this->fail($image->getError(), 400);
}
$data = [
'path' => $url.$filename,
'created_at' => date('Y-m-d H:i:s',time()),
'size' => $res->getSize(),
'hash' => hash(),
];
$imageModel = new ImageModel();
$imageModel->add($data);
return $data;
}
/**
* 生成缩略图缓存
* @param type $info
... ... @@ -46,16 +130,11 @@ class ImageController
* @param type $h
* @return string
*/
private function cacheImage($info, $w, $h, $type = 2) {
$thumbnailPath = './../uploads/image/';
$thumbnailImage = Image::make($info)
->fit($w, $h, function ($constraint) {
$constraint->upsize();
});
$thumbnailImage->save($thumbnailPath);
return $thumbnailPath;
return;
private function cacheImage($info, $w, $h) {
$path = './../'.$info['path'];
$filename = './../uploads/images/cache_'. $info['hash'] . $w . '_' . $h;
Image::make($path)->resize($w, $h)->save($filename);
return $filename;
}
/**
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\Project;
class ProjectLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Project();
$this->param = $this->requestAll;
}
}
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\ProjectRole;
class ProjectRoleLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new ProjectRole();
$this->param = $this->requestAll;
}
}
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Models\User;
class UserLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new User();
$this->param = $this->requestAll;
}
}
... ...
#!/usr/bin/env php
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any of our classes manually. It's great to relax.
|
*/
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);
... ... @@ -10,6 +10,7 @@
"doctrine/dbal": "^3.6",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"intervention/image": "^2.7",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
... ...
... ... @@ -174,7 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Intervention\Image\ImageServiceProvider::class,
// Intervention\Image\ImageServiceProvider::class,
],
... ... @@ -230,7 +230,7 @@ return [
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Image'=>Intervention\Image\ImageManagerStatic::class,
// 'Image'=>Intervention\Image\ImageManagerStatic::class,
],
];
... ...