|
@@ -7,6 +7,8 @@ use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Intervention\Image\Facades\Image;
|
|
use Intervention\Image\Facades\Image;
|
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
|
+use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
|
|
|
class UploadController extends Controller
|
|
class UploadController extends Controller
|
|
{
|
|
{
|
|
@@ -113,4 +115,65 @@ class UploadController extends Controller
|
|
return '仅支持mp3上传,请重试';
|
|
return '仅支持mp3上传,请重试';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 处理批量上传
|
|
|
|
+ */
|
|
|
|
+ public function uploadImagesChange(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
|
+ 'imgs' => 'required_if:type,image|array|max:9',
|
|
|
|
+ 'imgs.*' => 'required|url',
|
|
|
|
+ ]);
|
|
|
|
+ if ($validator->fails()) {
|
|
|
|
+ return $this->response->error($validator->errors()->first(), 500);
|
|
|
|
+ }
|
|
|
|
+ $data = [];
|
|
|
|
+ foreach($request['imgs'] as $img){
|
|
|
|
+ $res = $this->uploadOneImage($img);
|
|
|
|
+ if(!isset($res['data']['url'])){
|
|
|
|
+ return $this->response->error('上传失败,请重试', 500);
|
|
|
|
+ }
|
|
|
|
+ $data[] = config('customer.chxq_oss_url').$res['data']['url'];
|
|
|
|
+ }
|
|
|
|
+ return [
|
|
|
|
+ 'data' => $data
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function uploadOneImage($img) {
|
|
|
|
+ $path = public_path('image');
|
|
|
|
+ if (!file_exists($path)){
|
|
|
|
+ mkdir ($path,0777,true);
|
|
|
|
+ }
|
|
|
|
+ $fileUrl = $path.date('/Ymd').time(). uniqid() .'.jpg';
|
|
|
|
+ $content = file_get_contents($img);
|
|
|
|
+ file_put_contents($fileUrl, $content);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ $url = config("customer.manage_service_url").'/config/upload';
|
|
|
|
+ $array = [
|
|
|
|
+ 'multipart' => [
|
|
|
|
+ [
|
|
|
|
+ 'name' => 'image',
|
|
|
|
+ 'contents' => fopen($fileUrl, 'r'),
|
|
|
|
+ 'headers' => ['X-Baz' => 'bar'],
|
|
|
|
+ 'filename' => $fileUrl
|
|
|
|
+ ]
|
|
|
|
+ ],
|
|
|
|
+ 'query' => [],
|
|
|
|
+ 'http_errors' => false,
|
|
|
|
+ 'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
|
|
|
|
+ ];
|
|
|
|
+ $client = new \GuzzleHttp\Client();
|
|
|
|
+ $response = $client->request('post', $url, $array);
|
|
|
|
+ $result = json_decode($response->getBody()->getContents(), true);
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ $result = '';
|
|
|
|
+ }
|
|
|
|
+ unlink($fileUrl);
|
|
|
|
+ return $result;
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|