正在加载中···
BEAR's BLOG

laralver+vue 头像上传

发布时间:2018-11-23 15:33
效果图:
部分代码:
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class TestController extends Controller
{

public function index()
{
return view('test');
}

public function store(Request $request)
{
if ($image = $request->hasFile('avatar1')){
$file = $request->file('avatar1');
if($file->isValid()){
$destPath = realpath(public_path('uploads'));
if(file_exists($destPath)){
if(in_array(strtolower($file->extension()),['jpeg','jpg','gif','gpeg','png'])){
$newName = md5(time().rand(100000, 999999).$file->getClientOriginalName()).'.'.strtolower($file->extension());
if($file->move($destPath,$newName)){
return array('code'=> true);
}
}
}
}
}
return array('code'=> false);
}
}