Public Member Functions | Protected Member Functions

ilFileInputGUI Class Reference
[Services/Form]

This class represents a file property in a property form. More...

Inheritance diagram for ilFileInputGUI:
Collaboration diagram for ilFileInputGUI:

Public Member Functions

 __construct ($a_title="", $a_postvar="")
 Constructor.
 setValueByArray ($a_values)
 Set value by array.
 setSuffixes ($a_suffixes)
 Set Accepted Suffixes.
 getSuffixes ()
 Get Accepted Suffixes.
 enableFileNameSelection ($a_post_var)
 If enabled, users get the possibility to enter a filename for the uploaded file.
 isFileNameSelectionEnabled ()
 Check if filename selection is enabled.
 getFileNamePostVar ()
 Get file name post var.
 checkInput ()
 Check input, strip slashes etc.
 insert (&$a_tpl)
 Insert property html.

Protected Member Functions

 outputSuffixes ($a_tpl, $a_block="allowed_suffixes")
 getMaxFileSizeString ()

Detailed Description

This class represents a file property in a property form.

Author:
Alex Killing <alex.killing@gmx.de>
Version:
$Id$

Definition at line 31 of file class.ilFileInputGUI.php.


Constructor & Destructor Documentation

ilFileInputGUI::__construct ( a_title = "",
a_postvar = "" 
)

Constructor.

Parameters:
string $a_title Title
string $a_postvar Post Variable

Reimplemented from ilFormPropertyGUI.

Reimplemented in ilImageFileInputGUI.

Definition at line 40 of file class.ilFileInputGUI.php.

References ilFormPropertyGUI::setType().

        {
                parent::__construct($a_title, $a_postvar);
                $this->setType("file");
        }

Here is the call graph for this function:


Member Function Documentation

ilFileInputGUI::checkInput (  ) 

Check input, strip slashes etc.

set alert, if input is not ok.

Returns:
boolean Input ok, true/false

Reimplemented from ilFormPropertyGUI.

Definition at line 116 of file class.ilFileInputGUI.php.

References $filename, $lng, ilFormPropertyGUI::getPostVar(), ilFormPropertyGUI::getRequired(), getSuffixes(), ilFormPropertyGUI::setAlert(), and ilUtil::virusHandling().

        {
                global $lng;

                // remove trailing '/'
                while (substr($_FILES[$this->getPostVar()]["name"],-1) == '/')
                {
                        $_FILES[$this->getPostVar()]["name"] = substr($_FILES[$this->getPostVar()]["name"],0,-1);
                }

                $filename = $_FILES[$this->getPostVar()]["name"];
                $filename_arr = pathinfo($_FILES[$this->getPostVar()]["name"]);
                $suffix = $filename_arr["extension"];
                $mimetype = $_FILES[$this->getPostVar()]["type"];
                $size_bytes = $_FILES[$this->getPostVar()]["size"];
                $temp_name = $_FILES[$this->getPostVar()]["tmp_name"];
                $error = $_FILES[$this->getPostVar()]["error"];

                $_POST[$this->getPostVar()] = $_FILES[$this->getPostVar()];
                
                // error handling
                if ($error > 0)
                {
                        switch ($error)
                        {
                                case UPLOAD_ERR_INI_SIZE:
                                        $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
                                        return false;
                                        break;
                                         
                                case UPLOAD_ERR_FORM_SIZE:
                                        $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
                                        return false;
                                        break;
        
                                case UPLOAD_ERR_PARTIAL:
                                        $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
                                        return false;
                                        break;
        
                                case UPLOAD_ERR_NO_FILE:
                                        if ($this->getRequired())
                                        {
                                                $this->setAlert($lng->txt("form_msg_file_no_upload"));
                                                return false;
                                        }
                                        break;
         
                                case UPLOAD_ERR_NO_TMP_DIR:
                                        $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
                                        return false;
                                        break;
                                         
                                case UPLOAD_ERR_CANT_WRITE:
                                        $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
                                        return false;
                                        break;
         
                                case UPLOAD_ERR_EXTENSION:
                                        $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
                                        return false;
                                        break;
                        }
                }
                
                // check suffixes
                if ($_FILES[$this->getPostVar()]["tmp_name"] != "" &&
                        is_array($this->getSuffixes()))
                {
                        if (!in_array(strtolower($suffix), $this->getSuffixes()))
                        {
                                $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
                                return false;
                        }
                }
                
                // virus handling
                if ($_FILES[$this->getPostVar()]["tmp_name"] != "")
                {
                        $vir = ilUtil::virusHandling($temp_name, $filename);
                        if ($vir[0] == false)
                        {
                                $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
                                return false;
                        }
                }
                
                return true;
        }

Here is the call graph for this function:

ilFileInputGUI::enableFileNameSelection ( a_post_var  ) 

If enabled, users get the possibility to enter a filename for the uploaded file.

public

Parameters:
string post variable

Definition at line 82 of file class.ilFileInputGUI.php.

        {
                $this->filename_selection = true;
                $this->filename = $a_post_var;
        }

ilFileInputGUI::getFileNamePostVar (  ) 

Get file name post var.

public

Parameters:
string file name post var

Definition at line 106 of file class.ilFileInputGUI.php.

Referenced by insert().

        {
                return $this->filename;
        }

Here is the caller graph for this function:

ilFileInputGUI::getMaxFileSizeString (  )  [protected]

Definition at line 252 of file class.ilFileInputGUI.php.

Referenced by ilImageFileInputGUI::insert(), and insert().

        {
                // get the value for the maximal uploadable filesize from the php.ini (if available)
                $umf = get_cfg_var("upload_max_filesize");
                // get the value for the maximal post data from the php.ini (if available)
                $pms = get_cfg_var("post_max_size");
                
                //convert from short-string representation to "real" bytes
                $multiplier_a=array("K"=>1024, "M"=>1024*1024, "G"=>1024*1024*1024);
                
                $umf_parts=preg_split("/(\d+)([K|G|M])/", $umf, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
        $pms_parts=preg_split("/(\d+)([K|G|M])/", $pms, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
        
        if (count($umf_parts) == 2) { $umf = $umf_parts[0]*$multiplier_a[$umf_parts[1]]; }
        if (count($pms_parts) == 2) { $pms = $pms_parts[0]*$multiplier_a[$pms_parts[1]]; }
        
        // use the smaller one as limit
                $max_filesize = min($umf, $pms);

                if (!$max_filesize) $max_filesize=max($umf, $pms);
        
        //format for display in mega-bytes
                $max_filesize = sprintf("%.1f MB",$max_filesize/1024/1024);
                
                return $max_filesize;
        }

Here is the caller graph for this function:

ilFileInputGUI::getSuffixes (  ) 

Get Accepted Suffixes.

Returns:
array Accepted Suffixes

Definition at line 70 of file class.ilFileInputGUI.php.

Referenced by checkInput(), and outputSuffixes().

        {
                return $this->suffixes;
        }

Here is the caller graph for this function:

ilFileInputGUI::insert ( &$  a_tpl  ) 

Insert property html.

Reimplemented in ilImageFileInputGUI.

Definition at line 209 of file class.ilFileInputGUI.php.

References $lng, ilFormPropertyGUI::getFieldId(), getFileNamePostVar(), getMaxFileSizeString(), ilFormPropertyGUI::getPostVar(), isFileNameSelectionEnabled(), and outputSuffixes().

        {
                global $lng;
                
                // show filename selection if enabled
                if($this->isFileNameSelectionEnabled())
                {
                        $a_tpl->setCurrentBlock('filename');
                        $a_tpl->setVariable('POST_FILENAME',$this->getFileNamePostVar());
                        $a_tpl->setVariable('FILENAME_ID',$this->getFieldId());
                        $a_tpl->setVAriable('TXT_FILENAME_HINT',$lng->txt('if_no_title_then_filename'));
                        $a_tpl->parseCurrentBlock();
                }

                $this->outputSuffixes($a_tpl);
                
                $a_tpl->setCurrentBlock("prop_file");
                $a_tpl->setVariable("POST_VAR", $this->getPostVar());
                $a_tpl->setVariable("ID", $this->getFieldId());
                $a_tpl->setVariable("TXT_MAX_SIZE", $lng->txt("file_notice")." ".
                        $this->getMaxFileSizeString());
                $a_tpl->parseCurrentBlock();
        }

Here is the call graph for this function:

ilFileInputGUI::isFileNameSelectionEnabled (  ) 

Check if filename selection is enabled.

public

Returns:
bool enabled/disabled

Definition at line 94 of file class.ilFileInputGUI.php.

Referenced by insert().

        {
                return $this->filename_selection ? true : false;
        }

Here is the caller graph for this function:

ilFileInputGUI::outputSuffixes ( a_tpl,
a_block = "allowed_suffixes" 
) [protected]

Definition at line 233 of file class.ilFileInputGUI.php.

References $lng, and getSuffixes().

Referenced by ilImageFileInputGUI::insert(), and insert().

        {
                global $lng;
                
                if (is_array($this->getSuffixes()))
                {
                        $suff_str = $delim = "";
                        foreach($this->getSuffixes() as $suffix)
                        {
                                $suff_str.= $delim.".".$suffix;
                                $delim = ", ";
                        }
                        $a_tpl->setCurrentBlock($a_block);
                        $a_tpl->setVariable("TXT_ALLOWED_SUFFIXES",
                                $lng->txt("file_allowed_suffixes")." ".$suff_str);
                        $a_tpl->parseCurrentBlock();
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

ilFileInputGUI::setSuffixes ( a_suffixes  ) 

Set Accepted Suffixes.

Parameters:
array $a_suffixes Accepted Suffixes

Definition at line 60 of file class.ilFileInputGUI.php.

Referenced by ilImageFileInputGUI::__construct().

        {
                $this->suffixes = $a_suffixes;
        }

Here is the caller graph for this function:

ilFileInputGUI::setValueByArray ( a_values  ) 

Set value by array.

Parameters:
array $a_values value array

Definition at line 51 of file class.ilFileInputGUI.php.

        {
        }


The documentation for this class was generated from the following file: