Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpbfile.php
Go to the documentation of this file.
1 <?php
3 // $Id: ezpbfile.php 9329 2002-03-04 12:55:56Z ce $
4 //
5 // Definition of eZPBFile class
6 //
7 // Created on: <21-Sep-2000 11:22:21 bf>
8 //
9 // This source file is part of Exponential Basic, publishing software.
10 //
11 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
12 //
13 // This program is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU General Public License
15 // as published by the Free Software Foundation; either version 2
16 // of the License, or (at your option) any later version.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
26 //
27
30
46 //include_once( "kernel/classes/INIFile.php" );
47
48 class eZPBFile
49 {
53 function __construct()
54 {
55
56
57 }
58
66 function getUploadedFile( $name_var )
67 {
68 global $_FILES;
69
70 $name_var = $_FILES[ $name_var ];
71 $ret = true;
72
73 $this->FileName = $name_var['name'];
74 $this->FileType = $name_var['type'];
75 $this->FileSize = $name_var['size'];
76 $this->TmpFileName = $name_var['tmp_name'];
77
78 if ( ( $this->FileSize == "0" ) || ( $this->FileSize == "" ) || ( $this->FileName == "" ) )
79 {
80 $ret = false;
81 }
82
83 return $ret;
84 }
85
89 function dumpDataToFile( $data, $fileName )
90 {
91 $this->FileName = $fileName;
92 $ini =& eZINI::instance( 'site.ini' );
93 $tmpDir = $ini->variable( "site", "SiteTmpDir" );
94 $tmpfileName = tempnam( $tmpDir, "att" );
95 $this->TmpFileName = $tmpfileName;
96 $fh = fopen( $tmpfileName, 'wb' );
97 fwrite( $fh, $data );
98 fclose( $fh );
99 }
100
101
105 function dumpFroogleDataToFile( $data, $fileName )
106 {
107 $this->FileName = $fileName;
108 $ini =& eZINI::instance( 'site.ini' );
109 $tmpDir = $ini->variable( "site", "SiteFroogleExportDir" );
110 $tmpfileName = tempnam( $tmpDir, "att" );
111 $this->TmpFileName = $tmpfileName;
112 $fh = fopen( $tmpfileName, 'wb' );
113 fwrite( $fh, $data );
114 fclose( $fh );
115 }
116
120 function dumpYahooDataToFile( $data, $fileName )
121 {
122 $this->FileName = $fileName;
123 $ini =& eZINI::instance( 'site.ini' );
124 $tmpDir = $ini->variable( "site", "SiteYahooExportDir" );
125 $tmpfileName = tempnam( $tmpDir, "att" );
126 $this->TmpFileName = $tmpfileName;
127 $fh = fopen( $tmpfileName, 'wb' );
128 fwrite( $fh, $data );
129 fclose( $fh );
130 }
131
132
136 function getFile( $fileName )
137 {
138 $this->FileName = $fileName;
139 $this->FileSize = eZPBFile::filesize( $fileName );
140 $this->TmpFileName = $fileName;
141
142 $ret = true;
143
144 if ( ( $this->FileSize == "0" ) || ( $this->FileSize == "" ) )
145 {
146 $ret = false;
147 }
148 return $ret;
149 }
150
156 function move( $dest )
157 {
158 return move_uploaded_file( $this->TmpFileName, $dest );
159 }
160
166 function copy( $dest )
167 {
168 global $GlobalSiteIni;
169 if ( $dest != "" && $GlobalSiteIni)
170 {
171 $dest = $GlobalSiteIni->SiteDir . $dest;
172 }
173
174 $ret = true;
175
176 if ( !copy( $this->TmpFileName, $dest ) )
177 {
178 $ret = false;
179 }
180 else
181 chmod( $dest, 0644 );
182
183 return $ret;
184 }
185
189 function name()
190 {
191 return $this->FileName;
192 }
193
197 function type()
198 {
199 return $this->FileType;
200 }
201
205 function size()
206 {
207 return $this->FileSize;
208 }
209
220 public static function &siFileSize( $size )
221 {
222 $units = array( "GB" => 10737741824,
223 "MB" => 1048576,
224 "KB" => 1024,
225 "B" => 0 );
226 $decimals = 0;
227 $shortsize = $size;
228 foreach( $units as $unit_key => $val )
229 {
230 if ( $size >= $val )
231 {
232 $unit = $unit_key;
233 if ( $val > 0 )
234 {
235 $decimals = 2;
236 $shortsize = $size / $val;
237 }
238 break;
239 }
240 }
241 $shortsize = number_format( ( $shortsize ), $decimals);
242 $size = array( "size" => $size,
243 "size-string" => $shortsize,
244 "unit" => $unit );
245 return $size;
246 }
247
251 public function tmpName()
252 {
253 return $this->TmpFileName;
254 }
255
259 public function setType( $type )
260 {
261 $this->FileType = $type;
262 }
263
267 public static function file_exists( $filename )
268 {
269 global $GlobalSiteIni;
270 if ( $filename != "")
271 {
272 if ( $GlobalSiteIni )
273 {
274 $filename = $GlobalSiteIni->SiteDir . $filename;
275 }
276 // echo $filename ."<hr>";
277 return file_exists( $filename );
278 } else
279 {
280 return false;
281 }
282 }
283
287 public static function is_file( $filename )
288 {
289 global $GlobalSiteIni;
290 if ( $filename != "")
291 {
292 if ($GlobalSiteIni)
293 {
294 $filename = $GlobalSiteIni->SiteDir . $filename;
295 }
296 return is_file( $filename );
297 } else
298 {
299 return false;
300 }
301 }
302
306 public static function filemtime( $filename )
307 {
308 global $GlobalSiteIni;
309 if ( $filename != "" && $GlobalSiteIni)
310 {
311 $filename = $GlobalSiteIni->SiteDir . $filename;
312 }
313 if ( file_exists( $filename ) )
314 {
315 return filemtime( $filename );
316 }
317 else
318 {
319 return false;
320 }
321 }
322
326 public static function fopen( $filename, $options )
327 {
328 global $GlobalSiteIni;
329 if ( $filename != "" && $GlobalSiteIni)
330 {
331 $filename = $GlobalSiteIni->SiteDir . $filename;
332 }
333 return fopen( $filename, $options );
334 }
335
339 public static function filesize( $filename )
340 {
341 global $GlobalSiteIni;
342 if ( $filename != "" && $GlobalSiteIni)
343 {
344 $filename = $GlobalSiteIni->SiteDir . $filename;
345 }
346 return filesize( $filename );
347 }
348
352 public static function unlink( $filename )
353 {
354 global $GlobalSiteIni;
355 if ( $filename != "" && $GlobalSiteIni)
356 {
357 $filename = $GlobalSiteIni->SiteDir . $filename;
358 }
359
360 if( file_exists( $filename ) )
361 {
362 return @unlink( $filename );
363 }
364 else
365 return true;
366 }
367
371 public static function chmod( $filename, $mode )
372 {
373 global $GlobalSiteIni;
374 if ( $filename != "" && $GlobalSiteIni)
375 {
376 $filename = $GlobalSiteIni->SiteDir . $filename;
377 }
378 return chmod( $filename, $mode);
379 }
380
384 public static function dir( $dir, $add_sitedir = true )
385 {
386 global $GlobalSiteIni;
387 $ret = false;
388 if ( $add_sitedir )
389 {
390 if ( $dir != "" && $GlobalSiteIni)
391 {
392 $dir = $GlobalSiteIni->SiteDir . $dir;
393 }
394 }
395 $ret = dir( $dir );
396 return $ret;
397 }
398
402 public static function is_dir( $dir )
403 {
404 global $GlobalSiteIni;
405 if ( $dir != "" && $GlobalSiteIni)
406 {
407 $dir = $GlobalSiteIni->SiteDir . $dir;
408 }
409 return is_dir( $dir );
410 }
411
415 public static function realpath( $filename )
416 {
417 global $GlobalSiteIni;
418 if ( $filename != "" && $GlobalSiteIni)
419 {
420 $filename = $GlobalSiteIni->SiteDir . $filename;
421 }
422 return realpath( $filename );
423 }
424
428 public static function file( $filename )
429 {
430 if (file_exists( "kernel/sitedir.ini" ) && $filename != "" )
431 {
432 include( "kernel/sitedir.ini" );
433 $filename = $siteDir . $filename;
434 }
435 return file( $filename );
436 }
437
438 var $FileName;
439 var $TmpFileName;
440 var $FileType;
441 var $FileSize;
442 }
443
444 ?>
eZPBFile
Definition: ezpbfile.php:49
eZPBFile\fopen
static fopen( $filename, $options)
Definition: ezpbfile.php:326
eZPBFile\getFile
getFile( $fileName)
Definition: ezpbfile.php:136
eZPBFile\dumpFroogleDataToFile
dumpFroogleDataToFile( $data, $fileName)
Definition: ezpbfile.php:105
eZPBFile\$TmpFileName
$TmpFileName
Definition: ezpbfile.php:439
eZPBFile\siFileSize
static & siFileSize( $size)
Definition: ezpbfile.php:220
eZPBFile\$FileSize
$FileSize
Definition: ezpbfile.php:441
eZPBFile\name
name()
Definition: ezpbfile.php:189
eZPBFile\file_exists
static file_exists( $filename)
Definition: ezpbfile.php:267
eZPBFile\$FileType
$FileType
Definition: ezpbfile.php:440
eZPBFile\realpath
static realpath( $filename)
Definition: ezpbfile.php:415
eZPBFile\file
static file( $filename)
Definition: ezpbfile.php:428
eZPBFile\chmod
static chmod( $filename, $mode)
Definition: ezpbfile.php:371
eZPBFile\dir
static dir( $dir, $add_sitedir=true)
Definition: ezpbfile.php:384
eZPBFile\unlink
static unlink( $filename)
Definition: ezpbfile.php:352
eZPBFile\$FileName
$FileName
Definition: ezpbfile.php:438
eZPBFile\__construct
__construct()
Definition: ezpbfile.php:53
eZPBFile\getUploadedFile
getUploadedFile( $name_var)
Definition: ezpbfile.php:66
eZPBFile\copy
copy( $dest)
Definition: ezpbfile.php:166
eZPBFile\filemtime
static filemtime( $filename)
Definition: ezpbfile.php:306
eZPBFile\size
size()
Definition: ezpbfile.php:205
eZPBFile\setType
setType( $type)
Definition: ezpbfile.php:259
eZPBFile\filesize
static filesize( $filename)
Definition: ezpbfile.php:339
eZPBFile\dumpDataToFile
dumpDataToFile( $data, $fileName)
Definition: ezpbfile.php:89
eZPBFile\is_file
static is_file( $filename)
Definition: ezpbfile.php:287
eZPBFile\dumpYahooDataToFile
dumpYahooDataToFile( $data, $fileName)
Definition: ezpbfile.php:120
eZPBFile\tmpName
tmpName()
Definition: ezpbfile.php:251
eZPBFile\move
move( $dest)
Definition: ezpbfile.php:156
eZPBFile\type
type()
Definition: ezpbfile.php:197
eZPBFile\is_dir
static is_dir( $dir)
Definition: ezpbfile.php:402
$ini
$ini
Definition: classes/admin/linklist.php:64
$type
$type
Definition: classes/admin/linkselect.php:220
$siteDir
else $siteDir
Definition: cron_alerts.php:43
$GlobalSiteIni
$GlobalSiteIni
Definition: ezarticle/xmlrpc/xmlrpcserver.php:33
$fh
$fh
Definition: ezfilemanager/user/filedownload.php:254
$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
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$options
$options
Definition: optionlist.php:56
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.