Base64 format of foreground image, background processing mode
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) {
Determine if the upload is the original address
$a = Preg_match ('/.* (\.png|\.jpg|\.jpeg|\.gif) $/', $v);
if ($a) {
is stored unchanged, the file path is stored
$b = substr ($v, 36);
$result [$k] = $b;
}else{
No, just upload the picture.
$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;
}
}
}
Base64 image Upload Processing method