美文网首页
php方法封装

php方法封装

作者: 黄智健 | 来源:发表于2018-01-11 14:53 被阅读0次

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;

}

相关文章

网友评论

      本文标题:php方法封装

      本文链接:https://www.haomeiwen.com/subject/vdzznxtx.html