1. base64图片保存
public function base64_upload($base64)
{
//取出base64字符串
if (strstr($base64, ",")) {
$image = explode(',', $base64);
$image = $image[1];
}
$path = "uploads/sign/" . date('YmdHis', time());
//创建文件夹
if (!file_exists($path)) {
mkdir($path, 0700, true);
}
$image = base64_decode($image);
$image_path = $path . '/' . uniqid(). str_random(5). ".png";
if (file_put_contents($image_path, $image)) {
return $image_path;
}
return false;
}
2. 二维数组排序
/**二维数组排序
* @param $key排序字段
* @param int $sort SORT_ASC 升序 ,SORT_DESC 降序
* @param $arr二维数组
* @return array
*/
public function arr_sort($key, $sort = SORT_ASC, $arr)
{
$result = array();
foreach ($arr as $vo) {
$result[]= $vo[$key];
}
array_multisort($result, $sort, $arr);
return $arr;
}
网友评论