Пример #1
0
 function testGuessExtension()
 {
     MimeType::config('magic');
     MimeType::config('glob');
     $this->assertFalse(MimeType::guessExtension('i-m-not-a-mime-type'));
     $this->assertFalse(MimeType::guessExtension('/tmp/i-m-do-not-exist.txt'));
     /* Fails with null */
     // $this->assertEqual(MimeType::guessExtension('video/3gpp'), '3gp');
     // $this->assertEqual(MimeType::guessExtension('video/x-msvideo'), 'avi');
     $this->assertEqual(MimeType::guessExtension('application/x-bzip'), 'bz2');
     /* Fails with null */
     // $this->assertEqual(MimeType::guessExtension('video/mp4'), 'mp4');
     $this->assertEqual(MimeType::guessExtension('text/css'), 'css');
     $this->assertEqual(MimeType::guessExtension('audio/x-flac'), 'flac');
     $this->assertEqual(MimeType::guessExtension('application/x-shockwave-flash'), 'swf');
     $this->assertEqual(MimeType::guessExtension('image/gif'), 'gif');
     $this->assertEqual(MimeType::guessExtension('application/x-gzip'), 'gz');
     $this->assertEqual(MimeType::guessExtension('text/html'), 'html');
     $this->assertEqual(MimeType::guessExtension('audio/mpeg'), 'mp3');
     $this->assertEqual(MimeType::guessExtension('application/x-java'), 'class');
     $this->assertEqual(MimeType::guessExtension('application/javascript'), 'js');
     $this->assertEqual(MimeType::guessExtension('image/jpeg'), 'jpg');
     $this->assertEqual(MimeType::guessExtension('video/mpeg'), 'mpeg');
     /* Fails with ogg */
     // $this->assertEqual(MimeType::guessExtension('application/ogg'), 'ogx');
     /* Fails application<->text */
     // $this->assertEqual(MimeType::guessExtension('application/x-php'), 'php');
     $this->assertEqual(MimeType::guessExtension('application/pdf'), 'pdf');
     $this->assertEqual(MimeType::guessExtension('image/png'), 'png');
     $this->assertEqual(MimeType::guessExtension('application/postscript'), 'ps');
     $this->assertEqual(MimeType::guessExtension('text/x-gettext-translation'), 'po');
     $this->assertEqual(MimeType::guessExtension('text/x-gettext-translation-template'), 'pot');
     /* Fals with null */
     // $this->assertEqual(MimeType::guessExtension('application/x-gettext-translation'), 'mo');
     $this->assertEqual(MimeType::guessExtension('application/vnd.rn-realmedia'), 'rm');
     /* Fails application<->text */
     // $this->assertEqual(MimeType::guessExtension('application/rtf'), 'rtf');
     $this->assertEqual(MimeType::guessExtension('text/plain'), 'txt');
     $this->assertEqual(MimeType::guessExtension('application/msword'), 'doc');
     /* Fails with null */
     // $this->assertEqual(MimeType::guessExtension('application/vnd.openxmlformats-officedocument.wordprocessingml.document'), 'docx');
     $this->assertEqual(MimeType::guessExtension('application/vnd.oasis.opendocument.text'), 'odt');
     $this->assertEqual(MimeType::guessExtension('application/x-tar'), 'tar');
     $this->assertEqual(MimeType::guessExtension('audio/x-wav'), 'wav');
     $this->assertEqual(MimeType::guessExtension('application/xhtml+xml'), 'xhtml');
     $this->assertEqual(MimeType::guessExtension('application/xml'), 'xml');
 }
Пример #2
0
 /**
  * Stores the media to a file and assures that the output file has the correct extension
  *
  * @param string $file Absolute path to a file
  * @param boolean $overwrite Enable overwriting of an existent file
  * @return mixed
  */
 function store($file, $overwrite = false, $guessExtension = true)
 {
     $File = new File($file);
     if ($overwrite) {
         $File->delete();
     }
     if ($File->exists()) {
         $message = "Media::store - File `{$file}` already exists.";
         trigger_error($message, E_USER_NOTICE);
         return false;
     }
     if ($guessExtension) {
         $file = $File->Folder->pwd() . DS . $File->name();
         $correctExtension = MimeType::guessExtension($this->mimeType);
         if ($correctExtension) {
             $file .= '.' . $correctExtension;
         } elseif (isset($extension)) {
             $file .= '.' . $File->ext();
         }
     }
     if ($this->Adapters->dispatchMethod($this, 'store', array($file))) {
         return $file;
     }
     return false;
 }