Beispiel #1
0
 function getFormat($path)
 {
     try {
         $image = new BrImage($path);
         return $image->format();
     } catch (Exception $e) {
         return false;
     }
 }
 /**
  * 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;
 }