yupe\helpers\YFile::pathIsWritable PHP Method

pathIsWritable() public static method

public static pathIsWritable ( $name, $ext, $path ) : boolean | string
$name
$ext
$path
return boolean | string
    public static function pathIsWritable($name, $ext, $path)
    {
        if (self::checkPath($path)) {
            return $path . self::getTranslatedName($name) . '.' . $ext;
        } else {
            return false;
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function saveImage()
 {
     $quality = isset($this->resize['quality']) ? $this->resize['quality'] : 100;
     $width = isset($this->resize['width']) ? $this->resize['width'] : null;
     $height = isset($this->resize['height']) ? $this->resize['height'] : null;
     $tmpName = $this->_newImage->tempName;
     $imageName = $this->_getImageName();
     $image = Yii::app()->image->load($tmpName)->quality($quality);
     if (!($newFile = YFile::pathIsWritable($imageName, $image->ext, $this->uploadPath))) {
         throw new CHttpException(500, Yii::t('YupeModule.yupe', 'Directory "{dir}" is not acceptable for write!', array('{dir}' => $this->uploadPath)));
     }
     if ($width !== null && $image->width > $width || $height !== null && $image->height > $height) {
         $image->resize($width, $height);
     }
     if ($image->save($newFile)) {
         $this->owner->{$this->attributeName} = pathinfo($newFile, PATHINFO_BASENAME);
     }
 }