php 单张与多张图片上传保存到根目录

   
 //上传图片
    public function upload_imageApi(SysArticleImageRequest $Request)
    {
        $usrStr = $Request->getScheme() . '://' . $Request->getHost();
$fileInfos = $Request->file('files'); //接收上传的图片 $file_path = './upload/' . date("Y") . '/' . date("m") . '/' . date('d'); if (!is_dir($file_path)) { mkdir($file_path, 0777, true); } // print_r($fileInfos);exit; $new_path = []; foreach ($fileInfos as $key => $fileInfo) { // 得到扩展名 $ext = $fileInfo->getClientOriginalExtension(); // 生成最新名称 $file_name = date('YmdHis',time()).mt_rand(1000,9999) . '.' . $ext ; // 保存到指定地方 $fileInfo->move($file_path,$file_name); $new_path[] = $usrStr . substr($file_path,1) . '/' . $file_name; } return $new_path; }

  

 
posted @ 2024-06-26 14:46  俊豪(Alvin)  阅读(1)  评论(0编辑  收藏  举报