|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
+use Intervention\Image\Facades\Image;
|
|
|
|
|
|
class UploadController extends Controller
|
|
|
{
|
|
@@ -21,7 +22,15 @@ class UploadController extends Controller
|
|
|
// //获取文件的绝对路径,但是获取到的在本地不能打开
|
|
|
$filePath = $request->file('image')->getRealPath();
|
|
|
//要保存的文件名 时间+扩展名
|
|
|
- $filename = time() . '_' . uniqid() . '.' . $kuoname;
|
|
|
+ if (in_array($kuoname, ['jpg', 'jpeg', 'png'])) {
|
|
|
+ $width = Image::make($filePath)->width();
|
|
|
+ $height = Image::make($filePath)->height();
|
|
|
+ //要保存的文件名 时间+扩展名
|
|
|
+ $filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
|
|
|
+ } else {
|
|
|
+ //要保存的文件名 时间+扩展名
|
|
|
+ $filename = time() . '_' . uniqid() . '.' . $kuoname;
|
|
|
+ }
|
|
|
$imageUrl = Storage::put($path . $filename, file_get_contents($filePath));
|
|
|
if ($imageUrl) {
|
|
|
return [
|
|
@@ -44,7 +53,15 @@ class UploadController extends Controller
|
|
|
$kuoname = $files[$i]->getClientOriginalExtension();
|
|
|
$filePath = $files[$i]->getRealPath();
|
|
|
//要保存的文件名 时间+扩展名
|
|
|
- $filename = time() . '_' . uniqid() . '.' . $kuoname;
|
|
|
+ if (in_array($kuoname, ['jpg', 'jpeg', 'png'])) {
|
|
|
+ $width = Image::make($filePath)->width();
|
|
|
+ $height = Image::make($filePath)->height();
|
|
|
+ //要保存的文件名 时间+扩展名
|
|
|
+ $filename = time() . '_' . uniqid() . '*' . $width . '_' . $height . '.' . $kuoname;
|
|
|
+ } else {
|
|
|
+ //要保存的文件名 时间+扩展名
|
|
|
+ $filename = time() . '_' . uniqid() . '.' . $kuoname;
|
|
|
+ }
|
|
|
$imageUrl = Storage::put($filename, file_get_contents($filePath));
|
|
|
if ($imageUrl) {
|
|
|
array_push($urls, $filename);
|