海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
841 B

<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
/**
* 文件上传
* Class UploadController
* @package App\Http\Controllers\Api
*/
class UploadController extends Controller
{
private string $save_path = '/user/';
//图片上传
public function image(Request $request)
{
$image = $request->file('image');
if (empty($image) || !$image->isValid()) {
return $this->error('您未上传任何文件');
}
$mime = $image->getMimeType();
if (!in_array($mime, ['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg'])) {
return $this->error('上传图片格式错误');
}
$path = $request->image->store($this->save_path . 'images/' . $this->agent_id, 'public');
return $this->success(['path' => config('filesystems.disks.public.url') . '/' . $path]);
}
}