public function getPhoto(Request $request) { $photo = new \App\Photo(); if ($file = $request->image) { list($type, $imageData) = explode(';', $request->image); list(, $extension) = explode('/', $type); list(, $imageData) = explode(',', $imageData); $fileName = uniqid() . '.' . $extension; $source = fopen($request->image, 'r'); $destination = fopen('images/' . $fileName, 'w'); stream_copy_to_stream($source, $destination); fclose($source); fclose($destination); $photo = \App\Photo::create(['name' => $fileName]); return $photo; } return $photo; }
No comments:
Post a Comment