不在服务器中上传图片
<?php
function uploadImage($file,$dir,$thumb_dimension = null) // 1920 x 768
{
$path = public_path() . '/uploads' . $dir;
if (!File::exists($path)) {
File::makeDirectory($path, 0777, true, true);
}
$file_name = ucfirst($dir) . '-' . date('Ymdhis') . rand(0, 999) . " . " . $file->getClientOriginalExtension();
$success = $file->move($path, $file_name);
if ($success){
$file_path = $path.'/'.$file_name;
if ($thumb_dimension){
list($width,$height) = explode('x',$thumb_dimension);
Image::make($file_path)->resize(300,200,function ($constraint){
$constraint->aspectRatio();
})->save($path.'/Thumb-'.$file_name);
}
return $file_name;
}else{
return null;
}
}
不支持编码格式(jpg)。