DeTechn Blog

thinkphp5,单图和多图上传方法

<?php 
/**
 * 上传单图
 */
function upload($path,&nbsp;$filename)
{

    $file&nbsp;=&nbsp;request()-&gt;file($filename);

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

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

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

    $files&nbsp;=&nbsp;request()-&gt;file($filename);
    $path_list = '';
    foreach ($files&nbsp;as&nbsp;$file) {

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

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

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

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »