Пример #1
0
 /**
  * Save the file to the specified path
  * @return boolean TRUE on success
  */
 function save($path)
 {
     br()->importLib('Image');
     $dstFileName = '';
     $dstFilePath = '';
     $image = new BrImage($_FILES['qqfile']['tmp_name']);
     $md = md5_file($_FILES['qqfile']['tmp_name']);
     if (br($this->params, 'generateFileName')) {
         $dstFileName = $md . '.' . $image->format();
     } else {
         if (($onGetFileName = br($this->params, 'onGetFileName')) && gettype(br($this->params, 'onGetFileName')) == 'object') {
             $dstFileName = $onGetFileName(br()->fs()->fileName($this->getName()), $md);
         } else {
             if (br($this->params, 'saveToCharsSubFolder')) {
                 $dstFileName = br()->fs()->getCharsPath($md, br()->fs()->fileName($this->getName()));
             } else {
                 $dstFileName = br()->fs()->fileName(br()->fs()->normalizeFileName($this->getName()));
             }
         }
     }
     $dstFilePath = $path . $dstFileName;
     br()->fs()->createDir(br()->fs()->filePath($dstFilePath));
     if (!br($this->params, 'generateFileName') && br($this->params, 'checkExistance')) {
         $idx = 1;
         while (file_exists($dstFilePath)) {
             $dstFileName = br()->fs()->fileName($this->getName(), $idx);
             $dstFilePath = $path . $dstFileName;
             $idx++;
         }
     }
     if (file_exists($dstFilePath)) {
         unlink($dstFilePath);
     }
     if (move_uploaded_file($_FILES['qqfile']['tmp_name'], $dstFilePath)) {
         return $dstFileName;
     }
     return $dstFileName;
 }
Пример #2
0
 function generateThumbnail($src, $w, $h, $relativePath = null)
 {
     $path = $src;
     if (!preg_match('~^/~', $path) && !preg_match('~[A-Z]:\\\\~', $path)) {
         $path = br()->atBasePath($path);
     }
     if (!file_exists($path)) {
         $path = br()->atBasePath($path);
     }
     if (!file_exists($path) && $relativePath) {
         $path = $relativePath . $src;
     }
     if (!file_exists($path)) {
         return $src;
     }
     $pathinfo = pathinfo($path);
     $dst = str_replace($pathinfo['basename'], $w . 'x' . $h . '/' . $pathinfo['basename'], $src);
     $dstPath = $pathinfo['dirname'] . '/' . $w . 'x' . $h;
     br()->fs()->makeDir($dstPath);
     $dstPath .= '/' . $pathinfo['basename'];
     if (file_exists($dstPath)) {
         return $dst;
     } else {
         br()->log()->writeLn('Creating thumbnail from ' . $src . ' in ' . $dstPath);
         $image = new BrImage($path);
         $image->generateThumbnail($w, $h, $dstPath);
         return $dst;
     }
 }