头部引入-》use yii\web\UploadedFile;
$img = UploadedFile::getInstanceByName('img');$dir='uploads';//上传目录if (!is_dir($dir)){ mkdir($dir); //目录不存在则创建}@$name = $dir.'/'.$img->name; //文件名绝对路径$res= $img->saveAs($name,true); //保存文件if($res){ $sql = "insert into img (img) value ('$name')"; $data = \yii::$app->db->createCommand($sql)->query(); if($data){ echo "<script>alert('入库成功');location.href='?r=site/upload';</script>"; }}
yii2自带上传
最新推荐文章于 2022-11-01 15:32:47 发布