Open sidebar
public function storeImageByPayloadUrl(Request $request){ if ($url = $request->get('url')) { $ext = pathinfo($url, PATHINFO_EXTENSION); //$imageName = pathinfo($url, PATHINFO_FILENAME); $saveDir = public_path() . self::UPLOAD_DIR; $pathFile = $saveDir . '/' . time() . '.' .$ext; $relativePath = self::UPLOAD_DIR . '/' .time() . '.' . $ext; //dd($path); if(!is_dir($saveDir)) { File::makeDirectory($saveDir, 0777, true, true); } $httpClient = new Client(); $response = $httpClient->get( $url, [ RequestOptions::SINK => $pathFile, ] ); if ($response->getStatusCode() === 200) { $record = UploadImage::create([ 'path' => $relativePath, ]); $httpPath = config('app.url') . $record->path; return response([ 'success' => true, 'file' => [ 'url' => $httpPath ], "stretched" => true ]); } } }
Close sidebar
Back
Please note that all pasted data is publicly available.
X (fomerly Twitter)
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
X (fomerly Twitter)
GitHub
Use setting