Class CMS_fileUpload

Description

Class CMS_fileUpload

This class manages a file upload onto the server Need to give it at least a path representing the destination of uploaded file and the file input field name concerned (used like: $_FILES[$fieldname])

Intégration sample where "fieldname" is the name of file input field : // File upload management if ($_POST["edit_fieldname"]) { // comes from a radio to force deletion of previous file $o_file_upload = new CMS_fileUpload("fieldname", true); $o_file_upload->setPath('origin', $your_value_of_previous_file); // Delete previous file $o_file_upload->deleteOrigin(); // Proceed to upload if needed if ($_FILES["fieldname"]["name"] && $item->writeToPersistence()) { $o_file_upload->setPath('destination', $your_value_of_destination_path); if (!$o_file_upload->doUpload()) { $cms_message .= "Error message"; } } // Do something with filename on success $your_final_filename = $o_file_upload->getFilename(); }

Located in /automne/classes/files/fileupload.php (line 52)

CMS_grandFather
   |
   --CMS_fileUpload
Method Summary
 void __construct ([ $fieldname = false], [ $overwrite = false], string $fieldname,, boolean $overwrite,)
 boolean deleteOrigin ()
 boolean doUpload ()
 string getAttribute (string $name)
 string, getFilename ([ $key = 'destination'], string $key,)
 mixed, getInputValue ( $key, string $key,)
 string getPath ([ $key = false], string $key,)
 string, getPathBasedir ([ $key = 'destination'], string $key,)
 boolean inputFileTooWide ()
 boolean overwrite ()
 boolean ready ()
 void setAttribute (string $name, $value $value)
 boolean setPath ( $key,  $value, string $key,, string $value,)
 boolean _deletePathFile ( $key, string $key,)
 boolean _isValidPathKey ( $key, string $key,)
Methods
Constructor __construct (line 98)

Constructor

void __construct ([ $fieldname = false], [ $overwrite = false], string $fieldname,, boolean $overwrite,)
  • string $fieldname,: the name of the field containing file to upload (ex: $_FILES["fieldname"])
  • boolean $overwrite,: if set to true, deletes any previous file responding to $destinationPath before uploading new one
  • $fieldname
  • $overwrite
deleteOrigin (line 316)

Deletes file stored before fileUpload attempts to replace it Return true either file does not exists or file is deleted successfully This method is not called from doUpload(), use it manually first !

  • return: true if deletion succeeded, false otherwise
  • access: public
boolean deleteOrigin ()
doUpload (line 327)

Proceed to file upload

  • return: true if file upload successfully done, false otherwise
  • access: public
boolean doUpload ()
getAttribute (line 116)

Getter for any private attribute on this class

  • access: public
string getAttribute (string $name)
  • string $name
getFilename (line 259)

Gets one path filename

  • return: the filename
  • access: public
string, getFilename ([ $key = 'destination'], string $key,)
  • string $key,: which path ?
  • $key
getInputValue (line 289)

Gets an input field value (from $_FILES[$this->_fieldname][$key] Array)

  • return: the value of input file array
  • access: public
mixed, getInputValue ( $key, string $key,)
  • string $key,: which key corresponding to wanted value
  • $key
getPath (line 207)

Getter for a path, given its key in $_pathes attribute array

  • access: public
string getPath ([ $key = false], string $key,)
  • string $key,: which path ?
  • $key
getPathBasedir (line 300)

Get one path base directory

  • return: the directory
  • access: public
string, getPathBasedir ([ $key = 'destination'], string $key,)
  • string $key,: which path ?
  • $key
inputFileTooWide (line 273)

Check file size and server max uploading file size

  • return: true if too wide, false otherwise
  • access: public
boolean inputFileTooWide ()
overwrite (line 238)

Gets the overwrite behaviour

  • return: true if will overwrite, false otherwise
  • access: public
boolean overwrite ()
ready (line 248)

Says if there is something uploaded

  • return: true if ready to move upload
  • access: public
boolean ready ()
setAttribute (line 128)

Setter for any private attribute on this class

  • access: public
void setAttribute (string $name, $value $value)
  • string $name: name of attribute to set
  • $value $value: , the value to give
setPath (line 223)

Set a path, given its key

  • return: true on success, false otherwise
  • access: public
boolean setPath ( $key,  $value, string $key,, string $value,)
  • string $key,: which path ?
  • string $value,: value to set
  • $key
  • $value
_checkDestinationPath (line 152)

Check any file as destination path and delete it if $this->_overwrite attribute set to true

  • return: true if proceeded without any error, false otherwise
  • access: private
boolean _checkDestinationPath ()
_deletePathFile (line 182)

Check presence of a file and delete it

  • return: true if deletion succeeded, false otherwise
  • access: private
boolean _deletePathFile ( $key, string $key,)
  • string $key,: which path ?
  • $key
_isValidPathKey (line 141)

Check that given key (key in $_pathes attribute array) is valid

  • return: true if a good key, false otherwise
  • access: private
boolean _isValidPathKey ( $key, string $key,)
  • string $key,: the key to test
  • $key

Inherited Methods

Inherited From CMS_grandFather

 CMS_grandFather::autoload()
 CMS_grandFather::hasError()
 CMS_grandFather::log()
 CMS_grandFather::PHPErrorHandler()
 CMS_grandFather::raiseError()
 CMS_grandFather::setDebug()
 CMS_grandFather::setLog()
 CMS_grandFather::_raiseError()
 CMS_grandFather::__call()
Class Constants

Documentation generated on Wed, 15 Feb 2012 15:30:30 +0100 by phpDocumentor 1.4.3