Location: PHPKode > scripts > FuseBox Manager > fusebox-manager/FileUploadHandler.class.php
- author: Skakunov Alexander [hide@address.com]
- filename: FileUploadHandler.class.php
- date: FuseBoxManager.class.php
- description: FileUploadHandler class is work-around to track errors of file uploads. The work-around is necessary due to different features in PHP versions (see comments below)

class FileUploadHandler
  public $ok;
  protected $var_name;
  protected $files_array;
  public function FileUploadHandler($var_name, $files_array=array())
    $this->var_name = trim($var_name);
    $this->files_array = (array)(empty($files_array) ? $_FILES : $files_array);
    $this->ok = ($this->files_array[ $this->var_name ]['error']==UPLOAD_ERR_OK && 
                 !empty($this->files_array[ $this->var_name ]['tmp_name'])
  public function get_error_text()
    $arr_errors = array(
      'There is no error, the file uploaded with success',
      'The uploaded file exceeds the upload_max_filesize directive in php.ini',
      'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
      'The uploaded file was only partially uploaded',
      'No file was uploaded',
      'Missing a temporary folder', //Introduced in PHP 4.3.10 and PHP 5.0.3
      'Failed to write file to disk', //Introduced in PHP 5.1.0
      'File upload stopped by extension' //Introduced in PHP 5.2.0
    return $arr_errors[ $this->files_array[ $this->var_name ]['error'] ];
  public function get_file()
    return $this->files_array[ $this->var_name ]['tmp_name'];
  private function define_const()
    $arr_const = array(
      UPLOAD_ERR_NO_TMP_DIR, //Introduced in PHP 4.3.10 and PHP 5.0.3
      UPLOAD_ERR_CANT_WRITE, //Introduced in PHP 5.1.0
      UPLOAD_ERR_EXTENSION   //Introduced in PHP 5.2.0
    foreach($arr_const as $id => $const)
        define($const, $id);
Return current item: FuseBox Manager