• yii2图片上传


    yii2利用自带UploadedFile上传图片

    public static function uploadFile($name)
        {
            $uploadedFile = UploadedFile::getInstanceByName($name);        
            if($uploadedFile === null || $uploadedFile->hasError)
            {
                return null;
            }        
            $ymd = date("Ymd");        
            $save_path = dirname(Yii::$app->basePath).'\web\upload\images\'. $ymd . "\";
            $save_url = dirname(Yii::$app->homeUrl).'/upload/images/' . $ymd . "/";        
            if(! file_exists($save_path))
            {
                mkdir($save_path);
            }       
            $file_name = $uploadedFile->getBaseName();
            $file_ext = $uploadedFile->getExtension();        
            // 新文件名
            $new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;        
            $uploadedFile->saveAs($save_path . $new_file_name);       
            return ['path' => $save_path, 'url' => $save_url, 'name' => $file_name, 'new_name' => $new_file_name, 'ext' => $file_ext];
        }
  • 相关阅读:
    Currency Exchange
    Robot Motion
    Crashing Robots
    Parencodings
    Y2K Accounting Bug
    Tautology
    Power of Cryptography
    Radar Installation -poj 1328
    The Pilots Brothers' refrigerator
    【java】之cron表达式
  • 原文地址:https://www.cnblogs.com/baby123/p/4835089.html
Copyright © 2020-2023  润新知