<?php
namespace App\Http\Controllers;
use App\Models\Opinion;
use App\Models\Shops;
use App\Models\ShopSchool;
use App\Models\Updated;
use App\Models\User;
use Cache;
use Carbon\Carbon;
use Illuminate\Http\Request;
use PhpSms;
use Storage;
class CommonController extends Controller
{
public function uploadImage(Request $request)
{
if ($request->hasFile('upfile')) {
$file = $request->file('upfile');
$allowed_extensions = ['png', 'jpg', 'gif'];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => 'You may only upload png, jpg or gif.'];
}
$baseName =md5(time().str_random(10).uniqid());
$newName = $baseName.'.'.$file->getClientOriginalExtension();
$saveDir = 'upload/'.date('Y').'/'.date('m').'/'.date('d').'/';
$savePath = $saveDir.$newName;
$bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
if (Storage::exists($savePath)) return response()->json(['code'=>200,'msg'=>'上传成功','data'=>['uri'=>$savePath]]);
}
return response()->json(['code'=>500,'msg'=>'上传失败']);
}
//图片修改
public function postEditorUpload(Request $request)
{
if ($request->hasFile('upfile')) {
$file = $request->file('upfile');
$allowed_extensions = ['png', 'jpg', 'gif'];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => 'You may only upload png, jpg or gif.'];
}
$baseName =md5(time().str_random(10).uniqid()).'.'.$file->getClientOriginalExtension();
$newName = $baseName;
$saveDir = 'uploads/'.date('Y').'/'.date('m').'/'.date('d').'/';
$savePath = $saveDir.$newName;
// $bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
$bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
$size = Storage::size($savePath);
$url = $savePath;
if (Storage::e
namespace App\Http\Controllers;
use App\Models\Opinion;
use App\Models\Shops;
use App\Models\ShopSchool;
use App\Models\Updated;
use App\Models\User;
use Cache;
use Carbon\Carbon;
use Illuminate\Http\Request;
use PhpSms;
use Storage;
class CommonController extends Controller
{
public function uploadImage(Request $request)
{
if ($request->hasFile('upfile')) {
$file = $request->file('upfile');
$allowed_extensions = ['png', 'jpg', 'gif'];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => 'You may only upload png, jpg or gif.'];
}
$baseName =md5(time().str_random(10).uniqid());
$newName = $baseName.'.'.$file->getClientOriginalExtension();
$saveDir = 'upload/'.date('Y').'/'.date('m').'/'.date('d').'/';
$savePath = $saveDir.$newName;
$bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
if (Storage::exists($savePath)) return response()->json(['code'=>200,'msg'=>'上传成功','data'=>['uri'=>$savePath]]);
}
return response()->json(['code'=>500,'msg'=>'上传失败']);
}
//图片修改
public function postEditorUpload(Request $request)
{
if ($request->hasFile('upfile')) {
$file = $request->file('upfile');
$allowed_extensions = ['png', 'jpg', 'gif'];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => 'You may only upload png, jpg or gif.'];
}
$baseName =md5(time().str_random(10).uniqid()).'.'.$file->getClientOriginalExtension();
$newName = $baseName;
$saveDir = 'uploads/'.date('Y').'/'.date('m').'/'.date('d').'/';
$savePath = $saveDir.$newName;
// $bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
$bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
$size = Storage::size($savePath);
$url = $savePath;
if (Storage::e