Ejemplo n.º 1
0
 /**
  * Reads the file, detects the compression MIME type, closes the file
  * and returns the MIME type
  *
  * @param resource $file the file handle
  *
  * @return string the MIME type for compression, or 'none'
  */
 public static function getCompressionMimeType($file)
 {
     //Can't use PMA_StringMB here, so force use of PMA_StringNative.
     include_once 'libraries/StringNative.class.php';
     $pmaString = new PMA_StringNative();
     $test = fread($file, 4);
     $len = $pmaString->strlen($test);
     fclose($file);
     if ($len >= 2 && $test[0] == $pmaString->chr(31) && $test[1] == $pmaString->chr(139)) {
         return 'application/gzip';
     }
     if ($len >= 3 && $pmaString->substr($test, 0, 3) == 'BZh') {
         return 'application/bzip2';
     }
     if ($len >= 4 && $test == "PK") {
         return 'application/zip';
     }
     return 'none';
 }
 /**
  * Test for PMA_StringNative::strlen
  *
  * @param integer $length Length of the string
  * @param string  $str    String to check for
  *
  * @return void
  * @test
  * @dataProvider strlenData
  */
 public function testStrlen($length, $str)
 {
     $this->assertEquals($length, $this->testObject->strlen($str));
 }
 /**
  * Tests for strlen
  *
  * @param mixed $value Value to test
  *
  * @return void
  * @test
  * @dataProvider providerStrlen
  */
 public function testStrlen($value)
 {
     $native = $this->_native->strlen($value);
     $multibytes = $this->_mb->strlen($value);
     $this->assertTrue($native === $multibytes, 'native length: ' . var_export($native, true) . ' - mb length: ' . var_export($multibytes, true));
 }