Andreas94's avatar

Feedback for upload to CDN

Hi, I'm creating a function that allows you to check if in the database is 1 load on CDN if it is 0 load on the server.

function.php

function uCDN($dir, $name,  $x, $y)
{
	$immagine = Image::make($name)->fit($x, $y);
	$filename = rand().'-'.$dir.'.jpg';
	if (\App\Models\Setting::where('cdn', '1')->count() == 1)  {
		$resource = $immagine->stream()->detach();
		$path = Storage::disk('do_spaces')->put($dir.'/' . $filename,$resource);
	}  else {
			$immagine->save( public_path('upload/'. $dir .'/' . $filename ) );
	}
	return $filename;
}

Controller

      if(!empty($request->file('immagine'))) {
        $articoli->immagine = uCDN('news', $request->file('immagine'),'428','211');
      }

Do you have tips to improve it?

0 likes
1 reply

Please or to participate in this conversation.