Files
[ class tree: Files ] [ index: Files ] [ all elements ]

Class: Files

Source Location: /Files.php

Class Overview


This class manages Files objects.


Author(s):

Version:

  • 2.1

Variables

Methods



Class Details

[line 33]
This class manages Files objects.

Created on 01 jan 06

Changes: 2.0 -> 2.1: 28 jul 09 added: file is PEAR compatible added: to package Common 1.0 -> 2.0: updated: phpdoc compatible in the way to generate documentation




Tags:

author:  Pierre-Dominique Vienne <pvienne@me.com>
version:  2.1
license:  GNU Public License


[ Top ]


Class Variables

$blankicon =  "blank.png"

[line 102]

Variable that contains filename of blank icon



Tags:

access:  public

Type:   string


[ Top ]

$content_type =

[line 79]

Variable that contains content type of the specified filename



Tags:

access:  public

Type:   string


[ Top ]

$debug =  false

[line 114]

Variable that contains debug switch



Tags:

access:  public

Type:   bool


[ Top ]

$directory =

[line 49]

Variable that contains directory to be handled



Tags:

access:  public

Type:   string


[ Top ]

$error =

[line 119]

Variable that contains array of process errors



Tags:

access:  public

Type:   array


[ Top ]

$extension =

[line 64]

Variable that contains extension of the treated file



Tags:

access:  public

Type:   string


[ Top ]

$filecontent =

[line 74]

Variable that contains file content



Tags:

access:  public

Type:   string


[ Top ]

$filename =

[line 39]

Variable that contains filename to be handled



Tags:

access:  public

Type:   string


[ Top ]

$filename_noext =

[line 44]

Variable that contains filename to be handled without extension



Tags:

access:  public

Type:   string


[ Top ]

$icon_directory =  "images/v9/icons/files/"

[line 97]

Variable that contains icons path



Tags:

access:  public

Type:   string


[ Top ]

$img_ext = array(
        "jpg",
        "jpe",
        "jpeg",
        "gif",
        "png"
    )

[line 85]

Variable that contains web compatible image types extensions



Tags:

access:  protected

Type:   array


[ Top ]

$listing =

[line 108]

Variable that contains result array of Scan_Dir() function



Tags:

access:  public

Type:   array


[ Top ]

$mask =

[line 69]

Variable that contains octal permission mask



Tags:

access:  public

Type:   int


[ Top ]

$size =

[line 54]

Variable that contains octal size of the file



Tags:

access:  public

Type:   int


[ Top ]

$size_string =

[line 59]

Variable that contains octal size of the file (text formatted)



Tags:

access:  public

Type:   string


[ Top ]



Class Methods


method ContentType [line 931]

string ContentType( string $this->filecontent)

Content-Type detection function

This function is used to retrieve content type of a file. Result is returned.

  1.  <?php
  2.  $oFiles              new Files();
  3.  $oFiles->filecontent $filecontent;
  4.  echo $oFiles->ContentType();
  5.  // contenttypeofthefile
  6.  ?>




Tags:

return:  Content-Type of the file
since:  version 1.0
usedby:  Files::ReadableType()


Parameters:

string   $this->filecontent   content of the file to be checked (with headers) (required)

[ Top ]

method ConvertMask [line 630]

string ConvertMask( string $this->mask)

Mask conversion function

This function is used to convert octal fileperms mask to alpha like rwxr-xr-- Result is returned.

  1.  <?php
  2.  $oFiles       new Files();
  3.  $oFiles->mask 751;
  4.  echo $oFiles->ConvertMask();
  5.  // rwxr-x--x
  6.  ?>




Tags:

return:  file mask
since:  version 1.0


Parameters:

string   $this->mask   mask to be converted (required)

[ Top ]

method filesize_format [line 348]

string filesize_format( [bool $html_render = true], int $this->size)

Filesize formatting function

This function is used to convert a filesize in octets in the best filesize format (kB, MB, TB) Result is stored in $this->size_string and returned.

  1.  <?php
  2.  $oFiles                    new Files();
  3.  $oFiles->size            1024;
  4.  echo $oFiles->filesize_format();
  5.  // 1 KB
  6.  ?>




Tags:

return:  formatted string
since:  version 1.0


Parameters:

int   $this->size   size to be treated (required)
bool   $html_render   switch defining if space must be " " or "&nbsp;"

[ Top ]

method FreeSpace [line 479]

array FreeSpace( string $this->directory)

Space free calculation function

This function is used to get the freespace, totalspace and %age of freespace. Result is stored in $this->size and returned.

  1.  <?php
  2.  $oFiles                    new Files();
  3.  print_r($oFiles->FreeSpace());
  4.  // freespacearray
  5.  ?>




Tags:

return:  keys of array are "freespace", "totalspace", "percentage"
since:  version 1.0


Parameters:

string   $this->directory   directory to check

[ Top ]

method GetExtensionByFilename [line 575]

string GetExtensionByFilename( [bool $lowercase = false], string $this->filename)

Extension obtention function

This function is used to obtain the extension of a filename. Result is stored in $this->extension and returned.

  1.  <?php
  2.  $oFiles                  new Files();
  3.  $oFiles->filename        "foobar.xls";
  4.  echo $oFiles->GetExtensionByFilename();
  5.  // xls
  6.  ?>




Tags:

return:  file extension
since:  version 1.0
usedby:  Files::RandomName()
usedby:  BlueBox_CacheControl::ParseCache()
usedby:  Files::UploadFile()


Parameters:

string   $this->filename   filename to be checked (required)
bool   $lowercase   switch defining if return must be lower cased

[ Top ]

method GetIconByExtension [line 520]

string GetIconByExtension( string $this->extension, string $this->icon_directory)

Icon from extension obention function

This function is used to obtain an icon for a specific extension. (icon xls.png for xls files) Result is returned.

  1.  <?php
  2.  $oFiles                   new Files();
  3.  $oFiles->extension        "xls";
  4.  echo $oFiles->GetIconByExtension();
  5.  // images/v9/icons/files/xls.png
  6.  ?>




Tags:

return:  icon path
since:  version 1.0


Parameters:

string   $this->extension   extension to check icon (required)
string   $this->icon_directory   directory where to find icons

[ Top ]

method HeaderSize [line 1026]

int HeaderSize( string $this->filecontent)

File size from header detection function

This function is used to extract size from HTTP headers. Result is returned.

  1.  <?php
  2.  $oFiles              new Files();
  3.  $oFiles->filecontent $filecontent;
  4.  echo $oFiles->HeaderSize();
  5.  // 3482
  6.  ?>




Tags:

return:  filesize extract from header
since:  version 1.0


Parameters:

string   $this->filecontent   content of the file to be checked (with headers) (required)

[ Top ]

method http_filesize [line 792]

int http_filesize( string $sURL, [int $nTimeout = 30])

Filesize through HTTP protocol function

This function is used to retrieve size of a distant file via HTTP protocol. Original found at: http://www.tynril.info/index.php /2006/02/03/9-taille-d-un-fichier-distant-sur-un-serveur-http Result is returned.

  1.  <?php
  2.  $oFiles new Files();
  3.  $url    "http://www.foo.com/bar.html";
  4.  echo $oFiles->http_filesize($url);
  5.  // 3402
  6.  ?>




Tags:

return:  octal size of the file
since:  version 1.0


Parameters:

string   $sURL   URL of the file to be checked (required)
int   $nTimeout   timeout in seconds (default is 30s)

[ Top ]

method IsImage [line 706]

bool IsImage( [bool $webimg = true], string $this->filename)

Image detection function

This function is used to detect wheither or not the file is an image. Result is returned.

  1.  <?php
  2.  $oFiles           new Files();
  3.  $oFiles->filename "foo.jpg";
  4.  echo $oFiles->IsImage(true);
  5.  // 1
  6.  ?>




Tags:

return:  true if filename is an image (or web image when $webimg is set to true)
since:  version 1.0


Parameters:

string   $this->filename   name of the file to be checked (required)
bool   $webimg   switch defining if image must be a web image

[ Top ]

method RandomName [line 235]

string RandomName( [int $length = 32], string $filename)

Random rename function

This function is used to rename a file randomly. Result is returned and stored in $this->filename

  1.  <?php
  2.  $oFiles           new Files();
  3.  $oFiles->filename "foobar.ext";
  4.  echo $oFiles->RandomName(8);
  5.  // 93nxz2ls.ext
  6.  ?>




Tags:

return:  new filename
since:  version 1.0
usedby:  Files::UploadFile()
uses:  Files::GetExtensionByFilename()
uses:  Strings::MakeRandomPassword()


Parameters:

string   $filename   name of the file (used for extension definition)
int   $length   length of the string used as new filename

[ Top ]

method ReadableType [line 979]

bool ReadableType( string $this->filecontent)

Readable type detection function

This function is used to determine if a file type is text or binary. Result is returned.

  1.  <?php
  2.  $oFiles              new Files();
  3.  $oFiles->filecontent $filecontent;
  4.  echo $oFiles->ReadableType();
  5.  // 1
  6.  ?>




Tags:

return:  true if file is readable (text)
since:  version 1.0
uses:  MimeTypes::ReadableType()
uses:  Files::ContentType()


Parameters:

string   $this->filecontent   content of the file to be checked (with headers) (required)

[ Top ]

method RemoveExtension [line 884]

string RemoveExtension( string $this->filename)

Extension removing function

This function is used to retrieve a filename without extension. Result is stored in $this->filename_noext and returned.

  1.  <?php
  2.  $oFiles           new Files();
  3.  $oFiles->filename "foo.ext";
  4.  echo $oFiles->RemoveExtension();
  5.  // foo
  6.  ?>




Tags:

return:  filename without extension
since:  version 1.0


Parameters:

string   $this->filename   name of the file to be parsed (required)

[ Top ]

method RemoveHeader [line 1063]

string RemoveHeader( string $this->filecontent)

Header removal function

This function is used to remove HTTP headers. Result is returned.

  1.  <?php
  2.  $oFiles              new Files();
  3.  $oFiles->filecontent $filecontent;
  4.  echo $oFiles->RemoveHeader();
  5.  // filecontentwithoutheaders
  6.  ?>




Tags:

return:  file content without headers
since:  version 1.0


Parameters:

string   $this->filecontent   content of the file to be checked (with headers) (required)

[ Top ]

method ReturnBytes [line 420]

int ReturnBytes( string $this->size_string)

Filesize unformatting function

This function is used to convert a filesize in formatted form (for example: 8Mo or 8MB) in the octets form. Reverse engine of Files::filesize_format() Original function got on http://ch2.php.net/manual/fr/function.ini-get.php Result is stored in $this->size and returned.

  1.  <?php
  2.  $oFiles              new Files();
  3.  $oFiles->size_string KB;
  4.  echo $oFiles->filesize_format();
  5.  // 1024
  6.  ?>




Tags:

return:  size value
since:  version 1.0


Parameters:

string   $this->size_string   size string to be treated (required)

[ Top ]

method Scan_Dir [line 280]

void Scan_Dir( [bool $norecursivity = false], string $this->directory)

Directory scan function

This function is used to generate a filelisting of a directory and subdirs This function is a cousin of glob() which is included in PHP Libraries. Result is stored in $this->listing as a multi-dimensionnal array containing the filename, the directory and the concat of each ones

  1.  <?php
  2.  $oFiles                    new Files();
  3.  $oFiles->Scan_Dir();
  4.  print_r($oFiles->listing);
  5.  // directorylisting
  6.  ?>




Tags:

since:  version 1.0
usedby:  Files::Scan_Dir()
uses:  Files::Scan_Dir()


Parameters:

bool   $norecursivity   recursivity using switch
string   $this->directory   directory to scan (if none is submitted, current is used)

[ Top ]

method UploadFile [line 154]

bool UploadFile( string $rowname, [bool $randomrename = true], string $this->filename_noext, string $this->directory)

File upload function

This function is used to treat an uploaded file on server. Target destination directory is not created if it does not exist. It must also be writable. Result is returned

  1.  <?php
  2.  $oFiles            new Files();
  3.  $oFiles->directory "/foo/bar/";
  4.  echo $oFiles->UploadFile("uploadfile");
  5.  // /foo/bar/a6cvew783...32jc8.ext
  6.  ?>




Tags:

return:  true if file has been uploaded
since:  version 1.0
uses:  Files::RandomName()
uses:  Files::GetExtensionByFilename()


Parameters:

string   $rowname   name of the input in which the filename was posted (required)
bool   $randomrename   random rename switch
string   $this->filename_noext   new filename of the file on the server (WITHOUT EXTENSION)
string   $this->directory   directory where to put the file (required)

[ Top ]


Documentation generated on Wed, 26 Aug 2009 12:30:13 +0200 by phpDocumentor 1.4.1