cvs: pear /HTTP_Download Download.php

From: Date: Tue, 17 May 2005 10:55:19 +0000
Subject: cvs: pear /HTTP_Download Download.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-31891@lists.php.net to get a copy of this message
mike Tue May 17 06:55:19 2005 EDT Modified files: /pear/HTTP_Download Download.php Log: - implemented request #3283 - try to use MIME_Type to guess content type http://cvs.php.net/diff.php/pear/HTTP_Download/Download.php?r1=1.66&r2=1.67&ty=u Index: pear/HTTP_Download/Download.php diff -u pear/HTTP_Download/Download.php:1.66 pear/HTTP_Download/Download.php:1.67 --- pear/HTTP_Download/Download.php:1.66 Tue May 17 06:35:29 2005 +++ pear/HTTP_Download/Download.php Tue May 17 06:55:17 2005 @@ -17,7 +17,7 @@ * @author Michael Wallner <mike@php.net> * @copyright 2003-2005 Michael Wallner * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: Download.php,v 1.66 2005/05/17 10:35:29 mike Exp $ + * @version CVS: $Id: Download.php,v 1.67 2005/05/17 10:55:17 mike Exp $ * @link http://pear.php.net/package/HTTP_Download */ @@ -92,7 +92,7 @@ * if you want to send already gzipped data! * * @access public - * @version $Revision: 1.66 $ + * @version $Revision: 1.67 $ */ class HTTP_Download { @@ -572,11 +572,12 @@ /** * Guess content type of file * - * This only works if PHP is installed with ext/magic.mime AND php.ini - * is setup correct! Otherwise it will result in a FATAL ERROR. - * <b>So be WARNED!</b> + * First we try to use PEAR::MIME_Type, if installed, to detect the content + * type, else we check if ext/mime_magic is loaded and properly configured. * * Returns PEAR_Error if: + * o if PEAR::MIME_Type failed to detect a proper content type + * (HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE) * o ext/magic.mime is not installed, or not properly configured * (HTTP_DOWNLOAD_E_NO_EXT_MMAGIC) * o mime_content_type() couldn't guess content type or returned @@ -588,6 +589,13 @@ */ function guessContentType() { + if (class_exists('MIME_Type') || @include_once 'MIME/Type.php') { + if (PEAR::isError($mime_type = MIME_Type::autoDetect($this->file))) { + return PEAR::raiseError($mime_type->getMessage(), + HTTP_DOWNLOAD_E_INVALID_CONTENT_TYPE); + } + return $this->setContentType($mime_type); + } if (!function_exists('mime_content_type')) { return PEAR::raiseError( 'This feature requires ext/mime_magic!',

« previous php.pear.cvs (#31891) next »