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
775 B
33 lines
775 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 $save_path = '/uploads/';
|
|
|
|
//图片上传
|
|
public function image(Request $request)
|
|
{
|
|
$image = $request->file('image');
|
|
if (!$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]);
|
|
}
|
|
}
|