Search code examples
yii2subdomainurl-routingyii2-advanced-app

Yii2 saving to parent upload file from sub domain


Good Evening,

I have a sync from facebook using the API to download the images from an album and save to uploads in the root directory.

This was working perfectly but since going production i have had to swap to a subdomain due to shared hosting.

The line for the path i was using is as follows, how would i convert this to save from subdomain.

$path = Yii::getAlias('../uploads/fb/thumb/' . $id . '.jpg');


Solution

  • __DIR__.'/../uploads/fb/thumb/'
    
    $path = Yii::getAlias(__DIR__.'/../uploads/fb/thumb/' . $id . '.jpg');
    

    If a folder is fixed and specified, you can get help from the Url::to() or Url::toRoute :

    \yii\helpers\Url::to('path/yourFolder/');
    

    Or use Predefined Aliases here

    like: @webroot/..


    create a URL based on the currently requested route and GET parameters. >= 2.0.3

    echo \yii\helpers\Url::current(); // help?id=1 for example.com/help?id=1