search

Home  >  Q&A  >  body text

Use the upload class to customize the subdirectory generation method in tp3.2

private function savefiles($files,$student_id){
    $config=[
        'rootPath'      =>  WORKING_PATH.FILES_UPLOAD_PATH, //保存根路径
        'subName'       => array('creatSubName',$student_id),
    ];
    $upload = new Upload($config);
    $upload-> subName = array('creatSubName',$student_id);
    $uploadres = $upload->uploadOne($files);
    if ($uploadres){
        return $uploadres;
    }else{
        return false;
    }
}

public function creatSubName($student_id){
    dump("创建名字!");die;
    return $student_id;
}

If you write like this, you won’t be able to enter the creatSubName method, and it’s the same if you don’t pass in parameters. Please give me some advice

桃子桃子2211 days ago986

reply all(2)I'll reply

  • 桃子

    桃子2019-02-25 17:18:35

    The currently used savepath attribute in upload can be replaced to achieve the effect

    private function savefiles($files,$student_id){
        $config=[
            'rootPath'      =>  WORKING_PATH.FILES_UPLOAD_PATH, //保存根路径
            'autoSub'       =>  false, //自动子目录保存文件
            'savePath'       => $student_id.'/'.date('Y-m-d').'/',
        ];
        $upload = new Upload($config);
        $uploadres = $upload->uploadOne($files);
        if ($uploadres){
            return $uploadres;
        }else{
            return false;
        }
    }


    reply
    0
  • Cancelreply