Exemple #1
0
 /**
  * @param string $sFileName
  * @param string $sContentType
  * @param string $sMimeIndex = ''
  *
  * @return string
  */
 public function clearFileName($sFileName, $sContentType, $sMimeIndex = '')
 {
     $sFileName = 0 === strlen($sFileName) ? preg_replace('/[^a-zA-Z0-9]/', '.', (empty($sMimeIndex) ? '' : $sMimeIndex . '.') . $sContentType) : $sFileName;
     $sClearedFileName = preg_replace('/[\\s]+/', ' ', preg_replace('/[\\.]+/', '.', $sFileName));
     $sExt = \MailSo\Base\Utils::GetFileExtension($sClearedFileName);
     $iSize = 100;
     if ($iSize < strlen($sClearedFileName) - strlen($sExt)) {
         $sClearedFileName = substr($sClearedFileName, 0, $iSize) . (empty($sExt) ? '' : '.' . $sExt);
     }
     return \MailSo\Base\Utils::ClearFileName(\MailSo\Base\Utils::Utf8Clear($sClearedFileName));
 }
Exemple #2
0
 /**
  * @param string $sContentType
  * @param string $sFileName
  *
  * @return string
  */
 public static function ContentTypeType($sContentType, $sFileName)
 {
     $sResult = '';
     $sContentType = \strtolower($sContentType);
     if (0 === \strpos($sContentType, 'image/')) {
         $sResult = 'image';
     } else {
         switch ($sContentType) {
             case 'application/zip':
             case 'application/x-7z-compressed':
             case 'application/x-rar-compressed':
             case 'application/x-msdownload':
             case 'application/vnd.ms-cab-compressed':
             case 'application/x-gzip':
             case 'application/x-bzip':
             case 'application/x-bzip2':
             case 'application/x-debian-package':
                 $sResult = 'archive';
                 break;
             case 'application/msword':
             case 'application/rtf':
             case 'application/vnd.ms-excel':
             case 'application/vnd.ms-powerpoint':
             case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
             case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
             case 'application/vnd.openxmlformats-officedocument.wordprocessingml.template':
             case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
             case 'application/vnd.oasis.opendocument.text':
             case 'application/vnd.oasis.opendocument.spreadsheet':
                 $sResult = 'doc';
                 break;
             case 'application/pdf':
             case 'application/x-pdf':
                 $sResult = 'pdf';
                 break;
         }
         if ('' === $sResult) {
             switch (\strtolower(\MailSo\Base\Utils::GetFileExtension($sFileName))) {
                 case 'zip':
                 case '7z':
                 case 'rar':
                     $sResult = 'archive';
                     break;
             }
         }
     }
     return $sResult;
 }
 /**
  * @param string $sFileName
  *
  * @return bool
  */
 public function isFileHasThumbnail($sFileName)
 {
     static $aCache = array();
     $sExt = \MailSo\Base\Utils::GetFileExtension($sFileName);
     if (isset($aCache[$sExt])) {
         return $aCache[$sExt];
     }
     $bResult = \function_exists('gd_info');
     if ($bResult) {
         $bResult = false;
         switch ($sExt) {
             case 'png':
                 $bResult = \function_exists('imagecreatefrompng');
                 break;
             case 'gif':
                 $bResult = \function_exists('imagecreatefromgif');
                 break;
             case 'jpg':
             case 'jpeg':
                 $bResult = \function_exists('imagecreatefromjpeg');
                 break;
         }
     }
     $aCache[$sExt] = $bResult;
     return $bResult;
 }