Generate Health Reports
Public Function Uploadjkbg (Request $r) {
$data = $r->all ();
$JKBG [' jkbg_ctime '] = time ();
$JKBG [' jkbg_aid '] = \auth::user ()->id;
$JKBG [' jkbg_id '] = str_random (6). Mt_rand (100000, 999999);
Demo data
$data [' jkbg_pic '] = Array (0=> $base 64);
Upload image to server return path
if (!empty ($data [' jkbg_pic '])) {
$pic _arr = $this->uploadbaseima ($data [' jkbg_pic ']); This step puts the picture into the parameter is the picture Base64 array format
}else{
$pic _arr = Array ();
}
$JKBG [' jkbg_pic '] = Json_encode ($pic _arr);
Add a report
\db::begintransaction ();
$result = \db::table (' DXJK_JKBG ')->insert ($JKBG);
if (! $result) {
\db::rollback ();
\db::commit ();
return [' Code ' = 1001, ' data ' = [' message ' + ' upload report failed '];
}
Modify Upload Status
$ress = \db::table (' dxjk_admin ')->where (' id ', $JKBG [' Jkbg_aid '])->update ([' admin_status ' = 3]);
\db::commit ();
return [' Code ' = ' + ', ' data ' = [' message ' + ' upload report successful '];
}
Process picture information return the corresponding path
Public Function Uploadbaseima ($IMGARR) {
$result = Array ();
Set the path directly under uploads
if ($IMGARR) {
foreach ($imgArr as $k = = $v) {
if ($v) {
$address = $this->basechangeimg ($v);
$result [$k] = $address;
}else {
return Array ();
}
}
return $result;
}
}
Convert Base64 to local image
Public Function basechangeimg ($base)
{
Match the format of the picture
if (Preg_match ('/^ (data:\s*image\/(\w+); base64,)/', $base, $result)) {
$type = $result [2];
$path = '/base '. Date (' Ymd ', Time ()). "/";
$new _file = Public_path (' uploads '). $path;
if (!file_exists ($new _file)) {
Check if there is a folder, if not created, and give the highest permissions
mkdir ($new _file, 0700);
}
$name = Uniqid (). ". {$type} ";
$new _file = $new _file. $name;
if (file_put_contents ($new _file, Base64_decode (Str_replace ($result [1], ', $base)))) {
Return $path. $name;
} else {
return false;
}
}
}
Image upload method used in the project, Base64 save Local