function testGetStringMimeType() { if (\OC_Util::runningOnWindows()) { $this->markTestSkipped('[Windows] Strings have mimetype application/octet-stream on Windows'); } $result = OC_Helper::getStringMimeType("/data/data.tar.gz"); $expected = 'text/plain; charset=us-ascii'; $this->assertEquals($result, $expected); }
function testGetStringMimeType() { $result = OC_Helper::getStringMimeType("/data/data.tar.gz"); $expected = 'text/plain; charset=us-ascii'; $this->assertEquals($result, $expected); }
/** * Internal check to get the proper mimetype. * * This function would go over the available PHP methods to get * the MIME type. * * By default it will try to use the PHP fileinfo library which is * available from PHP 5.3 or as an PECL extension * (http://pecl.php.net/package/Fileinfo). * * It will get the magic file by default from the system wide file * which is usually available in /usr/share/magic on Unix or try * to use the file specified in the source directory of the API * (share directory). * * if fileinfo is not available it will try to use the internal * mime_content_type function. * * @param string $handle name of file or buffer to guess the type from * @return boolean <kbd>True</kbd> if successful * @throws BadContentTypeException */ function _guess_content_type($handle) { if ($this->content_type) { return; } // if (function_exists("finfo_open")) { // $local_magic = dirname(__FILE__) . "/share/magic"; // $finfo = @finfo_open(FILEINFO_MIME, $local_magic); // // if (!$finfo) // $finfo = @finfo_open(FILEINFO_MIME); // // if ($finfo) { // // if (is_file((string)$handle)) // $ct = @finfo_file($finfo, $handle); // else // $ct = @finfo_buffer($finfo, $handle); // // /* PHP 5.3 fileinfo display extra information like // charset so we remove everything after the ; since // we are not into that stuff */ // if ($ct) { // $extra_content_type_info = strpos($ct, "; "); // if ($extra_content_type_info) // $ct = substr($ct, 0, $extra_content_type_info); // } // // if ($ct && $ct != 'application/octet-stream') // $this->content_type = $ct; // // @finfo_close($finfo); // } // } // // if (!$this->content_type && (string)is_file($handle) && function_exists("mime_content_type")) { // $this->content_type = @mime_content_type($handle); // } //use OC's mimetype detection for files if (is_file($handle)) { $this->content_type = OC_Helper::getMimeType($handle); } else { $this->content_type = OC_Helper::getStringMimeType($handle); } if (!$this->content_type) { throw new BadContentTypeException("Required Content-Type not set"); } return True; }