首页 > Web开发 > 详细

yii2.0 多文件上传

时间:2015-04-23 18:00:21      阅读:282      评论:0      收藏:0      [点我收藏+]

$Fileobj = UploadedFile::getInstancesByName(‘file‘);

$leng = count($Fileobj);

for($i=0; $i<$leng; $i++) {

      $FileUrl[] = \Helper::SaveUploadFile($Fileobj[$i], ‘question‘);

}

public static function SaveUploadFile_avatar($file){

        $time = time();

        $targetPath = self::getImagePathInfo("avatar", true) .‘/‘. date(‘Ymd‘, $time);

        if(!is_dir($targetPath)){

            mkdir($targetPath, ‘0777‘, true);

        }

        $fileName = date(‘YmdHis‘, $time) . ‘_‘ . rand(10000, 99999) . ‘.‘ . strtolower($file->getExtensionName());

        $filePath = $targetPath . ‘/‘ . $fileName;

        if($file->saveAs($filePath)){

            if(self::resizeImage($filePath, 147, 147, $targetPath)){

                return ‘/‘.date(‘Ymd‘, $time) . ‘/‘ . $fileName;

            }else{

                return false;

            }

        }

    }


yii2.0 多文件上传

原文:http://jinliang.blog.51cto.com/8981814/1637569

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!