Class CMS_fileUpload_dialog

Description

Class CMS_fileUpload_dialog

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])

  • author: Cédric Soret <cedric.soret@ws-interactive.fr>
  • see: doUploadForResource() b) In any other situation : // an icon upload management for any purpose $o_file_upload = new CMS_fileUpload_dialog("file"); $o_file_upload->setOrigin($item->getIconPath(true, PATH_RELATIVETO_FILESYSTEM), $_POST["edit_file"]); if ($o_file_upload->ready() && $item->writeToPersistence()) { // Destination file personnalized $o_file_upload->setDestination($item->getIconPath(true, PATH_RELATIVETO_FILESYSTEM, false)."/cat-".$item->getID()."-icon".strrchr($_FILES["file"]["name"], ".")); } if (!$o_file_upload->doUpload()) { $cms_message .= $o_file_upload->getErrorMessage($cms_language); } else { $item->setIcon($o_file_upload->getFilename()); $item->writeToPersistence(); }
  • see: CMS_fileUpload Intégration samples (Where "file" is the $_FILES field name and $_POST["edit_file"] is used as a flag to determine if previous image has to be deleted before new upload) a) For a CMS_resource : // Image upload management $o_file_upload = new CMS_fileUpload_dialog("file"); $b_uploaded = $o_file_upload->doUploadForResource( $item, $cms_module->getCodename(), $item->getImagePath(true, RESOURCE_DATA_LOCATION_EDITED, PATH_RELATIVETO_FILESYSTEM), $_POST["edit_file"], (integer) $cms_module->getParameters("image_max_width") ); if (!$b_uploaded) { $cms_message .= $o_file_upload->getErrorMessage($cms_language); } else { $item->setImage($o_file_upload->getFilename()); $item->writeToPersistence(); }

Located in /automne/classes/dialogs/fileupload.php (line 70)

CMS_grandFather
   |
   --CMS_fileUpload_dialog
Class Constant Summary
Method Summary
 void __construct ([ $fieldname = false], [ $overwrite = false], string $fieldname,, boolean $overwrite,)
 boolean doUpload ()
 boolean doUploadForResource ( &$obj,  $moduleCodename, [ $originPath = false], [ $overwrite = false], [ $maxwidth = false], CMS_resource $obj,, string $moduleCodename,, string $originPath,, boolean $overwrite,, integer $maxwidth,)
 string getDestination ()
 string getErrorMessage ( &$cms_language)
 string, getFilename ()
 string getOrigin ()
 boolean ready ()
 boolean setDestination ( $value, string $value,)
 boolean setOrigin ( $value, [ $overwrite = false], string $value,)
Methods
Constructor __construct (line 115)

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
doUpload (line 209)

Proceed to file upload

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

For an easy acces from a CMS_resource management page

Sets the CMS_resource receiving the file uploaded and proceed to upload at the same time Given object must have these methods : getID() and writeToPersistence() they help determining thename of uploaded file

  • return: true on success, false otherwise
  • access: public
boolean doUploadForResource ( &$obj,  $moduleCodename, [ $originPath = false], [ $overwrite = false], [ $maxwidth = false], CMS_resource $obj,, string $moduleCodename,, string $originPath,, boolean $overwrite,, integer $maxwidth,)
  • CMS_resource $obj,: the object receiving file uploaded as a field
  • string $moduleCodename,: the module of the resource
  • string $originPath,: path of current file to delete before upload
  • boolean $overwrite,: if set to true, deletes any previous file
  • integer $maxwidth,: maxwidth allowed for an image
  • &$obj
  • $moduleCodename
  • $originPath
  • $overwrite
  • $maxwidth
getDestination (line 151)

Getter for destination path file

  • access: public
string getDestination ()
getErrorMessage (line 192)

Get error message if process fails somehow

  • access: public
string getErrorMessage ( &$cms_language)
  • &$cms_language
getFilename (line 172)

Get destination filename

  • return: the filename
  • access: public
string, getFilename ()
getOrigin (line 126)

Getter for origin path file

  • access: public
string getOrigin ()
ready (line 182)

Says if there is something uploaded

  • return: true if ready to move upload
  • access: public
boolean ready ()
setDestination (line 162)

Set destination path

  • return: true on success, false otherwise
  • access: public
boolean setDestination ( $value, string $value,)
  • string $value,: value to set
  • $value
setOrigin (line 137)

Set origin path

  • return: true on success, false otherwise
  • access: public
boolean setOrigin ( $value, [ $overwrite = false], string $value,)
  • string $value,: value to set
  • $value
  • $overwrite

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
MESSAGE_ERROR_FILE_TOO_WIDE = 1193 (line 76)
MESSAGE_ERROR_FILE_UPLOAD = 196 (line 75)

Messages

MESSAGE_ERROR_IMAGE_TOO_WIDE = 1596 (line 77)

Inherited Constants

Inherited from CMS_grandFather

CMS_grandFather::ERROR_LOG
CMS_grandFather::SYSTEM_LABEL

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