diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 0d816b6..d5034c6 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -56,15 +56,18 @@ class ItemController extends Controller $newitem['wo'] = ""; $item = Item::create($newitem); - $pos = strpos( $request->get('dataImage') , "," ); - //$head = substr($request->get('dataImage'), 0, $pos); - $image = base64_decode(substr($request->get('dataImage'), $pos+1), true); - if($image) { - $hash = md5(time()); - if (!file_exists('staticimages')) - mkdir('staticimages', 0755, true); - file_put_contents('staticimages/'. $hash, $image); - $file = File::create(array('hash' => $hash, 'iid' => $item['iid'])); + if ($request->get('dataImage')) { + $pos = strpos($request->get('dataImage'), ","); + //$head = substr($request->get('dataImage'), 0, $pos); + $image = base64_decode(substr($request->get('dataImage'), $pos + 1), true); + if ($image) { + $hash = md5(time()); + if (!file_exists('staticimages')) + mkdir('staticimages', 0755, true); + file_put_contents('staticimages/' . $hash, $image); + $file = File::create(array('hash' => $hash, 'iid' => $item['iid'])); + $item['file'] = $hash; + } } return response()->json($item, 201); } @@ -89,6 +92,7 @@ class ItemController extends Controller mkdir('staticimages', 0755, true); file_put_contents('staticimages/' . $hash, $image); $file = File::create(array('hash' => $hash, 'iid' => $item['iid'])); + $item['file'] = $hash; } } return response()->json($item, 200);