public static function uploadUrl($path = '', $uploadsAlias = '@uploads', $webfilesurlAlias = 'uploads')
    {
        $path = str_replace('\\', '/', $path);
        $webroot = str_replace('\\', '/', Yii::getAlias('@webroot'));
        $uploads = str_replace('\\', '/', Yii::getAlias($uploadsAlias));

        //$subdir = str_replace($webroot, '', $uploads); // work correct only if uploads path is insite web root
        $subdir = str_replace($uploads, '', $path);

        $web = Yii::getAlias('@web'); 
        $files = Yii::getAlias($webfilesurlAlias);
        $result = $web . (empty($web) ? '' : '/' ) . $files . $subdir;

        return $result;
    }
public static function uploadUrl($path = '', $uploadsAlias = '@uploads', $webfilesurlAlias = 'uploads')
    {
        $path = str_replace('\\', '/', $path);
        $webroot = str_replace('\\', '/', Yii::getAlias('@webroot'));
        $uploads = str_replace('\\', '/', Yii::getAlias($uploadsAlias));

        //$subdir = str_replace($webroot, '', $uploads); // work correct only if uploads path is insite web root
        $subdir = str_replace($uploads, '', $path);

        $web = Yii::getAlias('@web'); 
        $files = Yii::getAlias($webfilesurlAlias);
        $result = $web . (empty($web) ? '' : '/' ) . $files . $subdir;

        return $result;
    }
public static function uploadUrl ( $ path = '' , $ uploadsAlias = '@uploads' , $ webfilesurlAlias = 'uploads' ) { $ path = str_replace ( '\\' , '/' , $ path ) ; $ webroot = str_replace ( '\\' , '/' , Yii :: getAlias ( '@webroot' ) ) ; $ uploads = str_replace ( '\\' , '/' , Yii :: getAlias ( $ uploadsAlias ) ) ; //$subdir = str_replace($webroot, '', $uploads); // work correct only if uploads path is insite web root $ subdir = str_replace ( $ uploads , '' , $ path ) ; $ web = Yii :: getAlias ( '@web' ) ; $ files = Yii :: getAlias ( $ webfilesurlAlias ) ; $ result = $ web . ( empty ( $ web ) ? '' : '/' ) . $ files . $ subdir ; return $ result ; }
Convert upload path to web URL.
Work only if alias @uploads is subdir of alias @webroot.
@param string $path
@param string $uploadsAlias alias for uploads path in filesystem (non-standard for Yii2)
@param string $webfilesurlAlias alias/subdir - path from webroot to uploads directory
@return string
Convert upload path to web URL . Work only if alias