php - convert image to base 64 string with Laravel -


i want convert image base 64 laravel. image form . tried in controller:

public function newevent(request $request){     $parametre =$request->all();      if ($request->hasfile('image')) {         if($request->file('image')->isvalid()) {             try {                 $file = $request->file('image');                 $image = base64_encode($file);                 echo $image;               } catch (filenotfoundexception $e) {                 echo "catch";              }         }     } 

i only:

l3rtcc9wahbya0nqqlq=

laravel's $request->file() doesn't return actual file content. returns instance of uploadedfile-class.

you need load actual file able convert it:

$image = base64_encode(file_get_contents($request->file('image')->pat‌​h())); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -