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.
|
|
<?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 $save_path = '/uploads/';
//图片上传
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('images', 'uploads'); return $this->success(['path' => env('APP_URL') . $this->save_path . $path]); }}
|