/** * Constructor. * * @param string $stored_filename The stored name of the file. * @param string $orig_filename The original name of the file. */ public function __construct($stored_filename, $orig_filename = '') { if (\pdyn\datatype\Validator::filename($stored_filename) !== true) { throw new \Exception('Invalid filename received', 400); } if (!empty($orig_filename) && !is_scalar($orig_filename)) { throw new \Exception('Uploaded file orig filename must be scalar or empty', 400); } $this->stored_filename = \pdyn\filesystem\FilesystemUtils::sanitize_filename($stored_filename); $this->orig_filename = \pdyn\filesystem\FilesystemUtils::sanitize_filename($orig_filename); }
/** * Assign values to class properties. * * @param array $info An array of data to assign. * @return bool Success/Failure. */ protected function populate(array $info = array()) { if (empty($info)) { $this->post_populate(); return false; } // Load datatype information into static var cache. $obj_datatypes = static::get_obj_datatypes($this->DB); $info = array_intersect_key($info, $obj_datatypes); foreach ($info as $key => $val) { switch ($obj_datatypes[$key]) { case 'email': if (\pdyn\datatype\Validator::email($val)) { $this->{$key} = (string) $val; } break; case 'timestamp': if ((int) $val > 0) { $this->{$key} = (int) $val; } break; case 'str': case 'text': case 'longtext': $this->{$key} = (string) $val; break; case 'filename': $val = trim($val); if (!empty($val)) { $this->{$key} = \pdyn\filesystem\FilesystemUtils::sanitize_filename($val); } break; case 'int': case 'bigint': $this->{$key} = (int) $val; break; case 'float': $this->{$key} = (double) $val; break; case 'id': $this->{$key} = (int) $val; break; case 'bool': $this->{$key} = (bool) $val; break; case 'user_id': if (\pdyn\datatype\Id::validate($val) === true) { $this->{$key} = (int) $val; } break; case 'url': if (\pdyn\datatype\Url::validate($val) === true) { $this->{$key} = (string) $val; } break; case 'mime': if (\pdyn\datatype\Validator::mime($val) === true) { $this->{$key} = (string) $val; } break; default: if (is_array($obj_datatypes[$key])) { if (in_array($val, $obj_datatypes[$key], true)) { $this->{$key} = $val; } } else { $this->{$key} = $val; } } } $this->post_populate(); return true; }