thinkphp5,单图,多图,上传


/**
 * 上传单图
 */
function upload($path, $filename)
{

    $file = request()->file($filename);

    $info = $file->rule('uniqid')->validate(['size' => 200 * 1024 * 1024, 'ext' => 'jpeg,jpg,png,gif'])->move($path);

    if ($info) {
        return $info;
    } else {
        $this->error($file->getError());
    }
}

//框架多图上传
function arrUpload($path, $filename)
{

    $files = request()->file($filename);
    $path_list = '';
    foreach ($files as $file) {

        $info = $file->rule('uniqid')->validate(['size' => 2 * 1024 * 1024, 'ext' => 'jpg,png,gif'])->move($path);
        if ($info) {

            $path_list[] = $info->getSaveName();
        } else {

            $this->error($file->getError());
        }
    }
    return $path_list;
}

posted @ 2019-01-05 15:03  sfornt  阅读(351)  评论(0编辑  收藏  举报