yupe\helpers\YFile::checkPath PHP Method

checkPath() public static method

public static checkPath ( $path, integer $rights = 511, boolean $recursive = true ) : boolean
$path
$rights integer
$recursive boolean
return boolean
    public static function checkPath($path, $rights = 0777, $recursive = true)
    {
        if (empty($path)) {
            return false;
        }
        if (!is_dir($path)) {
            // проверка на существование директории
            return mkdir($path, $rights, $recursive);
            // возвращаем результат создания директории
        } else {
            if (!is_writable($path)) {
                // проверка директории на доступность записи
                return false;
            }
        }
        return true;
        // папка существует и доступна для записи
    }

Usage Example

Beispiel #1
0
 /**
  * @param string $file Полный путь к исходному файлу в файловой системе
  * @param string $uploadDir Подпапка в папке с миниатюрами куда надо поместить изображение
  * @param float $width Ширина изображения. Если не указана - будет вычислена из высоты
  * @param float $height Высота изображения. Если не указана - будет вычислена из ширины
  * @param array $options
  * @return string
  * @throws CException
  */
 public function thumbnail($file, $uploadDir, $width = 0, $height = 0, array $options = ['jpeg_quality' => 90, 'png_compression_level' => 8])
 {
     if (!$width && !$height) {
         throw new CException("Incorrect width/height");
     }
     $name = $width . 'x' . $height . '_' . basename($file);
     $uploadPath = $this->getBasePath() . DIRECTORY_SEPARATOR . $uploadDir;
     $thumbFile = $uploadPath . DIRECTORY_SEPARATOR . $name;
     if (!file_exists($thumbFile)) {
         if (false === YFile::checkPath($uploadPath)) {
             throw new CException(Yii::t('YupeModule.yupe', 'Directory "{dir}" is not acceptable for write!', ['{dir}' => $uploadPath]));
         }
         $img = Imagine::getImagine()->open($file);
         $originalWidth = $img->getSize()->getWidth();
         $originalHeight = $img->getSize()->getHeight();
         if (!$width) {
             $width = $height / $originalHeight * $originalWidth;
         }
         if (!$height) {
             $height = $width / $originalWidth * $originalHeight;
         }
         if ($width / $originalWidth > $height / $originalHeight) {
             $box = new Box($width, $originalHeight * $width / $originalWidth);
         } else {
             $box = new Box($originalWidth * $height / $originalHeight, $height);
         }
         $img->resize($box)->crop(new Point(max(0, round(($box->getWidth() - $width) / 2)), max(0, round(($box->getHeight() - $height) / 2))), new Box($width, $height))->save($thumbFile, $options);
     }
     $url = $this->getBaseUrl() . '/' . $uploadDir . '/' . $name;
     return $url;
 }
All Usage Examples Of yupe\helpers\YFile::checkPath