Initialize preferences
public initialize ( array $config = [], boolean $reset = TRUE ) : CI_Upload | ||
$config | array | |
$reset | boolean | |
return | CI_Upload |
function initialize($params = array()) { $CI =& get_instance(); if (!empty($params['field'])) { $this->field = $params['field']; } parent::initialize($params); }
function initialize($params = array()) { $CI =& get_instance(); if (!empty($params['field'])) { $this->field = $params['field']; $params['upload_path'] = './data/' . $CI->_name . '/' . $params['field']; if (!file_exists($params['upload_path'])) { @mkdir($params['upload_path'], 0777, true); } } parent::initialize($params); }
function initialize($params = array()) { parent::initialize($params); if (count($params) > 0) { foreach ($params as $key => $val) { if (isset($this->{$key})) { $this->{$key} = $val; } } } $this->upload_path = 'data/' . $this->data_dir; if (!file_exists($this->upload_path)) { mkdir($this->upload_path, 0777, true); } if (is_string($this->allowed_types)) { $this->set_allowed_types($this->allowed_types); } }
/** * Keep the file in the temp directory? * * @access public */ public function initialize($config = array()) { if (isset($config['use_temp_dir']) && $config['use_temp_dir'] === TRUE) { $this->use_temp_dir = TRUE; } else { $this->use_temp_dir = FALSE; } parent::initialize($config); }
/** * Initialize preferences * * $config = array( * 'document_root' Absolute path. Root from where all other paths will be defined. * No tampering to parent folder possible * Cannot be send by the request * 'upload_path' Relative path from the document_root in where the uploaded file will be stored * Completes the document_root. No tampering to parent folder possible * Cannot be send by the request * Ionize : 'files/' * 'directory' Relative path from '/document_root/upload_path/' * Can be send by request. * Overwritten by the do_upload() $config settings if it exists (to avoid user send) * No tampering to parent folder possible * 'safe' If set to TRUE, all file types will be allowed * Else, only the extensions set in 'allowed_extensions' are allowed * 'allowed_extensions' '*' : Allow all extensions * Array : Array of allowed extensions * Used by is_allowed_extension() if 'safe' = true * and to prepare the file name : _prep_filename() (remove of the part extensions * 'clean_foreign_chars' Set to TRUE, converts all foreign chars during the filename cleaning process * 'resize_image' Resize the image to 'resize_width' and 'resize_height' if the file is one image * 'resize_width' and 'resize_height' must be set. * The resize maintains image proportions. * ) * * @param array * @return void */ public function initialize($config = array()) { parent::initialize($config); $defaults = array('safe' => FALSE, 'clean_foreign_chars' => TRUE, 'allowed_extensions' => array(), 'document_root' => $_SERVER['DOCUMENT_ROOT'], 'new_folder_chmod' => 0777, 'resize_image' => FALSE, 'resize_width' => 0, 'resize_height' => 0); foreach ($defaults as $key => $val) { if (isset($config[$key])) { $this->{$key} = $config[$key]; } else { $this->{$key} = $val; } } // Foreign Chars : Text Helper if ($this->clean_foreign_chars) { $CI =& get_instance(); $CI->load->helper('text'); } // Sanitize of the upload path $this->document_root = $this->normalize($this->document_root); $this->upload_path = $this->normalize($this->document_root . $this->upload_path); log_message('debug', 'MY_Upload initialized'); }