Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezfilemanager/user/filedownload.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: filedownload.php 9808 2003-04-11 13:48:48Z br $
5 //
6 // Created on: <10-Dec-2000 16:39:10 bf>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
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 the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "ezfilemanager/classes/ezvirtualfile.php" );
28 // include_once( "ezuser/classes/ezuser.php" );
29 // include_once( "ezuser/classes/ezobjectpermission.php" );
30
31 $ini =& eZINI::instance( 'site.ini' );
32
33 $user =& eZUser::currentUser();
34
35 $file = new eZVirtualFile( $FileID );
36
37 if ( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user ) == false )
38 {
39 eZHTTPTool::header( "Location: /error/403/" );
40 exit();
41 }
42
43 $fileName = $file->name();
44
45 if ( $ini->variable( "eZFileManagerMain", "DownloadOriginalFilename" ) == "true" && $file->originalFileName() != "" )
46 $originalFileName = $file->originalFileName();
47 else
48 $originalFileName = $file->name();
49
50 $filePath = $file->filePath( true );
51 // echo "<hr>"; svar_dump( $filePath ); echo "<hr>";
52 $userID = $user->ID;
53
54 $file_debug = true;
55 $download_style_inline = true;
56
57 //###################################################
58 // nsb non-requred nsb authentication
59
60 /*
61 if( $userID == '')
62 die("sucka!!");
63 */
64
65 /*
66 if ( $userID < 2 ) {
67 if ( $userID != '' ) {
68 // print ("USER ID : '". $userID ."'");
69
70 if ( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user ) == false )
71 {
72 print ("USER With Permission : '". $userID ."'<br>");
73 }
74
75 }
76
77 // print ("USER ID : is Null");
78 //exit();
79 }
80 */
81
82 //###################################################
83 // nsb non-requred nsb authentication
84
85 /*
86 if ( ( $userID != '' ) && ( $userID != 0 ) )
87 {
88 */
89 //###################################################
90
91 //include_once( "ezstats/classes/ezpageview.php" );
92
93 if ( !isset( $GlobalPageView ) )
94 {
95 $GlobalPageView = new eZPageView();
96 $GlobalPageView->store();
97 }
98
99 $editedFileName = str_replace( " ", "%20", $originalFileName );
100
101 // store the statistics
102 $file->addPageView( $GlobalPageView );
103
104 $filePath = preg_replace( "#.*/(.*)#", "\\1", $filePath );
105
106 if($file_debug){
107 print( $filePath );
108
109 print( "Location: /filemanager/filedownload/$filePath/$editedFileName" );
110 exit();
111 }
112
113
114 /*
115 }
116 */
117
118 //###################################################
119 // nsb required user authentication download
120 //###################################################
121
122 /*
123 // $host = $SERVER_NAME;
124 // $location = "Location: http://" . $SERVER_NAME . ":" . $SERVER_PORT . "/" . $wwwDir . $index . "filemanager/filedownload/$filePath/$editedFileName";
125
126 //if ( eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user ) == false )
127
128 if ( ( $userID == '' ) && ($userID == 0 ) )
129 {
130 // include( "ezuser/user/login.php" );
131 $fileID = $file->id();
132
133 // $RedirectURL = "/filemanager/download/$fileID";
134
135 // Create a new session, store it to the database and set a cookie.
136 // $session =& eZSession::globalSession( );
137 // $session->store();
138
139 // get the session from the client
140 // The page must reload before the session cookie is accessable.
141 // $session->fetch();
142
143 // set a session variable
144 // $session->setVariable( "RedirectURL", "$RedirectURL" );
145
146 // fetch the CartID session variable
147 // $cartID = $session->variable( "CartID" );
148
149
150 // eZHTTPTool::header( "Location: $RedirectURL" );
151 // die($RedirectURL);
152
153 // eZHTTPTool::header( "Location: /error/nouser/" );
154 // exit();
155 }
156
157
158 // print( $location );
159 // Header( $location );
160 */
161
162 //###################################################
163
164 // Rewrote to be compatible with virtualhost-less install
165 $size = eZPBFile::filesize( "var/site/storage/ezfilemanager/$filePath" );
166
167 $nameParts = explode( ".", $editedFileName );
168 $suffix = $nameParts[count( $nameParts ) - 1];
169
170 $suffix = strtolower( $suffix );
171
172 if($file_debug) {
173 print("your file is: " . $suffix ."<br />");
174 print("your file is: " . $editedFileName ."<br />");
175 die("your file is: " . $originalFileName );
176 }
177
178 //-----------------------------------------
179 // clear what might be in the output buffer and stop the buffer.
180 ob_end_clean();
181 switch ( $suffix )
182 {
183 case "gif" :
184 case "GIF" :
185 header( "Content-Type: image/gif" );
186 break;
187 case "jpeg" :
188 case "JPEG" :
189 header( "Content-Type: image/jpeg" );
190 break;
191 case "png" :
192 case "PNG" :
193 header( "Content-Type: image/jpeg" );
194 break;
195 case "JPG" :
196 case "jpg" :
197 header( "Content-Type: image/jpg" );
198 break;
199 case "txt" :
200 case "TXT" :
201 header( "Content-Type: text/plain" );
202 break;
203 case "zip" :
204 case "ZIP" :
205 header( "Content-Type: application/zip" );
206 break;
207 case "doc" :
208 case "DOC" :
209 header( "Content-Type: application/msword" );
210 break;
211 case "ppt" :
212 case "PPT" :
213 header( "Content-Type: application/vnd.ms-powerpoint" );
214 break;
215 case "xls" :
216 case "XLS" :
217 header( "Content-Type: application/vnd.ms-excel" );
218 break;
219 case "PDF" :
220 case "pdf" :
221 header( "Content-Type: application/pdf" );
222 break;
223 default :
224 header( "Content-Type: application/octet-stream" );
225 break;
226 }
227
228 // xxx
229 if($file_debug){
230 die("PDF: " . $suffix);
231 }
232
233 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
234 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
235 header("Pragma: public");
236 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
237
238 header( "Accept-Ranges: bytes" );
239
240 // header( "Cache-Control:" );
241 header( "Content-Length: $size" );
242
243 if(!$download_style_inline){
244 // can you make them download outside the main window ... not like this
245 header( "Content-disposition: attachment; filename=$editedFileName" );
246 // header( "Content-disposition: filename=$editedFileName" );
247 } else {
248 // inline download (for pdfs)
249 header( "Content-disposition: inline; filename=$editedFileName" );
250 header( "Content-Transfer-Encoding: binary" );
251 }
252
253 // include the file's contents to browser ...
254 $fh = eZPBFile::fopen( "var/site/storage/ezfilemanager/$filePath", "rb" );
255 fpassthru( $fh );
256 exit();
257
258 // original exit method
259 // break();
260
261 ?>
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZObjectPermission\hasPermission
static hasPermission( $objectID, $moduleTable, $permission, $user=false)
Definition: ezobjectpermission.php:76
eZPBFile\fopen
static fopen( $filename, $options)
Definition: ezpbfile.php:326
eZPBFile\filesize
static filesize( $filename)
Definition: ezpbfile.php:339
eZPageView
Definition: ezpageview.php:47
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFile
Definition: ezvirtualfile.php:42
$fh
$fh
Definition: ezfilemanager/user/filedownload.php:254
$file_debug
$file_debug
Definition: ezfilemanager/user/filedownload.php:54
$nameParts
$nameParts
Definition: ezfilemanager/user/filedownload.php:167
$fileName
if(eZObjectPermission::hasPermission( $file->id(), "filemanager_file", "r", $user)==false) $fileName
Definition: ezfilemanager/user/filedownload.php:43
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$download_style_inline
$download_style_inline
Definition: ezfilemanager/user/filedownload.php:55
$user
$user
Definition: ezfilemanager/user/filedownload.php:33
$editedFileName
if(!isset( $GlobalPageView)) $editedFileName
Definition: ezfilemanager/user/filedownload.php:99
$suffix
$suffix
Definition: ezfilemanager/user/filedownload.php:168
$ini
$ini
Definition: ezfilemanager/user/filedownload.php:31
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$filePath
$filePath
Definition: ezfilemanager/user/filedownload.php:50
$originalFileName
else $originalFileName
Definition: ezfilemanager/user/filedownload.php:48
$userID
$userID
Definition: ezfilemanager/user/filedownload.php:52
exit
exit
Definition: folder.php:81
$GlobalPageView
$GlobalPageView
Definition: storestats.php:43
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.