return file property on update and create to show image imidiately

This commit is contained in:
j3d1 2019-12-29 13:36:32 +01:00
parent b349690996
commit 47dcc79752

View file

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