FileHelper saveAs and createDirectory issues

Hi,

I posted this in #7462 but @SilverFire pointed me out here and blocked the thread before I could even defend myself… :slight_smile:

Before the behavior change cited in #7462 I had:

In params-local.php:




 return ['myRoot' => '@web/myroot'];



…and in controller:




$fullPath = Yii::$app->params[$myRoot] . '/myLast';

FileHelper::createDirectory($fullPath); // same behavior with saveAs



and had no trouble with it. Now, following the code replacement recommended in #6289 I have:




FileHelper::createDirectory(Yii::getAlias($fullPath)); //same behavior with saveAs



And it throws:

Exception – yii\base\Exception

Failed to create directory ‘/web’: mkdir(): Permission denied

In summary, I had no permission issues with pre-#7462 code but now I do after applying the recommended replacement and that’s why I assumed my question to properly fit in the context of #7462 rather than posting it in the forums.

Anyway, any idea?

Antonio

In those issues (#7462 and #6289), they were discussing whether aliases should be supported or not for certain circumstances. They were talking about the design, not bugs.

And the issues were closed since the dev team had already decided not to.

It’s not your fault, but you were asking question about a bug.

In the following 2 codes, createDirectory receives different parameters. It’s normal that one may succeed and the other may fail. Check the parameters passed to createDirectory.




$fullPath = Yii::$app->params[$myRoot] . '/myLast';

FileHelper::createDirectory($fullPath);






$fullPath = Yii::$app->params[$myRoot] . '/myLast';

FileHelper::createDirectory(Yii::getAlias($fullPath));