Skip to content

Commit

Permalink
correct check if image dir is writable
Browse files Browse the repository at this point in the history
  • Loading branch information
karpoff committed Oct 24, 2015
1 parent 5cb49fe commit 1b858ff
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions CropImageUploadBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,17 @@ public function beforeValidate()

$model->setAttribute($this->attribute, $crops['file']);

if (!is_writable(\Yii::getAlias($this->resolvePath($this->path)))) {
$model->addError($this->attribute, 'image path is not writable ');
$path = $this->resolvePath($this->path);
if (!is_writable(\Yii::getAlias($path))) {
$cp = [];
foreach (explode('/', $path) as $p) {
if (preg_match('/{([^}]+)}/', $p))
break;
$cp[] = $p;
}
if (!is_writable(\Yii::getAlias(implode('/', $cp)))) {
$model->addError($this->attribute, 'image path is not writable ' . \Yii::getAlias($this->resolvePath($this->path)));
}
}
}

Expand Down

0 comments on commit 1b858ff

Please sign in to comment.