[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZBinaryFileHandler class 4 // 5 // Created on: <30-Apr-2002 16:47:08 bf> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! 30 \class eZFilePasstroughHandler ezfilepasstroughhandler.php 31 \ingroup eZBinaryHandlers 32 \brief Handles file downloading by passing the file trough PHP 33 34 */ 35 include_once ( "kernel/classes/datatypes/ezbinaryfile/ezbinaryfile.php" ); 36 include_once ( "kernel/classes/ezbinaryfilehandler.php" ); 37 define( "EZ_FILE_PASSTROUGH_ID", 'ezfilepasstrough' ); 38 39 class eZFilePasstroughHandler extends eZBinaryFileHandler 40 { 41 function eZFilePasstroughHandler() 42 { 43 $this->eZBinaryFileHandler( EZ_FILE_PASSTROUGH_ID, "PHP passtrough", EZ_BINARY_FILE_HANDLE_DOWNLOAD ); 44 } 45 46 function handleFileDownload( &$contentObject, &$contentObjectAttribute, $type, 47 $fileInfo ) 48 { 49 $fileName = $fileInfo['filepath']; 50 51 // VS-DBFILE 52 53 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 54 $file = eZClusterFileHandler::instance( $fileName ); 55 56 if ( $fileName != "" and $file->exists() ) 57 { 58 $file->fetch(); 59 $fileSize = $file->size(); 60 $mimeType = $fileInfo['mime_type']; 61 $originalFileName = $fileInfo['original_filename']; 62 $contentLength = $fileSize; 63 $fileOffset = false; 64 $fileLength = false; 65 if ( isset( $_SERVER['HTTP_RANGE'] ) ) 66 { 67 $httpRange = trim( $_SERVER['HTTP_RANGE'] ); 68 if ( preg_match( "/^bytes=([0-9]+)-$/", $httpRange, $matches ) ) 69 { 70 $fileOffset = $matches[1]; 71 header( "Content-Range: bytes $fileOffset-" . $fileSize - 1 . "/$fileSize" ); 72 header( "HTTP/1.1 206 Partial content" ); 73 $contentLength -= $fileOffset; 74 } 75 } 76 // Figure out the time of last modification of the file right way to get the file mtime ... the 77 $fileModificationTime = filemtime( $fileName ); 78 79 ob_clean(); 80 header( "Pragma: " ); 81 header( "Cache-Control: " ); 82 /* Set cache time out to 10 minutes, this should be good enough to work around an IE bug */ 83 header( "Expires: ". gmdate('D, d M Y H:i:s T', time() + 600) ); 84 header( "Last-Modified: ". gmdate( 'D, d M Y H:i:s T', $fileModificationTime ) ); 85 header( "Content-Length: $contentLength" ); 86 header( "Content-Type: $mimeType" ); 87 header( "X-Powered-By: eZ publish" ); 88 header( "Content-disposition: attachment; filename=\"$originalFileName\"" ); 89 header( "Content-Transfer-Encoding: binary" ); 90 header( "Accept-Ranges: bytes" ); 91 92 $fh = fopen( "$fileName", "rb" ); 93 if ( $fileOffset ) 94 { 95 eZDebug::writeDebug( $fileOffset, "seeking to fileoffset" ); 96 fseek( $fh, $fileOffset ); 97 } 98 99 ob_end_clean(); 100 fpassthru( $fh ); 101 fclose( $fh ); 102 fflush( $fh ); 103 104 // VS-DBFILE : NOTE: We don't remove fetched file here to avoid refetching on each download. 105 // We may need a way to purge obsolete files though. 106 107 //$file->deleteLocal(); 108 109 eZExecution::cleanExit(); 110 } 111 return EZ_BINARY_FILE_RESULT_UNAVAILABLE; 112 } 113 } 114 115 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |