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'] = "";
$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);