00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 include_once( "kernel/classes/datatypes/ezbinaryfile/ezbinaryfile.php" );
00038 include_once( "kernel/classes/ezbinaryfilehandler.php" );
00039 define( "EZ_FILE_PASSTROUGH_ID", 'ezfilepasstrough' );
00040
00041 class eZFilePasstroughHandler extends eZBinaryFileHandler
00042 {
00043 function eZFilePasstroughHandler()
00044 {
00045 $this->eZBinaryFileHandler( EZ_FILE_PASSTROUGH_ID, "PHP passtrough", EZ_BINARY_FILE_HANDLE_DOWNLOAD );
00046 }
00047
00048 function handleFileDownload( &$contentObject, &$contentObjectAttribute, $type,
00049 $fileInfo )
00050 {
00051 $fileName = $fileInfo['filepath'];
00052
00053
00054
00055 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00056 $file = eZClusterFileHandler::instance( $fileName );
00057
00058 if ( $fileName != "" and $file->exists() )
00059 {
00060 $file->fetch();
00061 $fileSize = $file->size();
00062 $mimeType = $fileInfo['mime_type'];
00063 $originalFileName = $fileInfo['original_filename'];
00064 $contentLength = $fileSize;
00065 $fileOffset = false;
00066 $fileLength = false;
00067 if ( isset( $_SERVER['HTTP_RANGE'] ) )
00068 {
00069 $httpRange = trim( $_SERVER['HTTP_RANGE'] );
00070 if ( preg_match( "/^bytes=([0-9]+)-$/", $httpRange, $matches ) )
00071 {
00072 $fileOffset = $matches[1];
00073 header( "Content-Range: bytes $fileOffset-" . ( $fileSize - 1 ) . "/$fileSize" );
00074 header( "HTTP/1.1 206 Partial content" );
00075 $contentLength -= $fileOffset;
00076 }
00077 }
00078
00079 $fileModificationTime = filemtime( $fileName );
00080
00081 ob_clean();
00082 header( "Pragma: " );
00083 header( "Cache-Control: " );
00084
00085 header( "Expires: ". gmdate('D, d M Y H:i:s T', time() + 600) . ' GMT' );
00086 header( "Last-Modified: ". gmdate( 'D, d M Y H:i:s T', $fileModificationTime ) . ' GMT' );
00087 header( "Content-Length: $contentLength" );
00088 header( "Content-Type: $mimeType" );
00089 header( "X-Powered-By: eZ publish" );
00090 header( "Content-disposition: attachment; filename=\"$originalFileName\"" );
00091 header( "Content-Transfer-Encoding: binary" );
00092 header( "Accept-Ranges: bytes" );
00093
00094 $fh = fopen( "$fileName", "rb" );
00095 if ( $fileOffset )
00096 {
00097 eZDebug::writeDebug( $fileOffset, "seeking to fileoffset" );
00098 fseek( $fh, $fileOffset );
00099 }
00100
00101 ob_end_clean();
00102 fpassthru( $fh );
00103 fclose( $fh );
00104 fflush( $fh );
00105
00106
00107
00108
00109
00110
00111 eZExecution::cleanExit();
00112 }
00113 return EZ_BINARY_FILE_RESULT_UNAVAILABLE;
00114 }
00115 }
00116
00117 ?>