/** * @uses FileExtension */ public function __construct($file, $do_exit = true) { list($width, $height, $mime_type, $attr) = getimagesize($file); if (!is_string($mime_type)) { $extension = new FileExtension($file); switch ($extension->__toString()) { case 'jpg': case 'jpeg': $image_type = \IMAGETYPE_JPEG; break; case 'gif': $image_type = \IMAGETYPE_GIF; break; case 'png': $image_type = \IMAGETYPE_PNG; break; default: throw new \Exception("Could not determine image type from filename"); break; } $mime_type = image_type_to_mime_type($image_type); } header("Content-type: " . $mime_type); readfile($file); if ($do_exit) { exit; } }
protected function beforeValidate() { if (empty($this->instanceId) && empty($this->tmpId)) { $this->addError('instanceId', 'Не указан instanceId.'); } $file = CUploadedFile::getInstance($this, 'file'); if ($file) { foreach (self::$deniedExtensions as $ext) { if (strpos($file->getName(), '.' . $ext) !== false) { $this->addError('file', 'Файл имеет запрещенное расширение.'); return false; } } } $objectParameter = $this->getObjectParameter(); //если есть ограничение по типу файлов, то нужно добавить в валидатор if ($objectParameter && ($addParam = $objectParameter->getAdditionalParameter())) { $types = FileExtension::getExtensionsByType($addParam); $validators = $this->getValidators('file'); if (isset($validators[0]) && $validators[0] instanceof CFileValidator) { $validators[0]->types = $types; } } return parent::beforeValidate(); }
public function uninstall() { if (parent::uninstall()) { return parent::setUnInstalled(); } else { return false; } }
public function find_contract($dir, $id_user = null) { $contract_array = array(); $directory = new _Directory(); if ($id_user == null) { $this->QUERY = "SELECT id_contrato , nombre , contrato , " . "aceptado , fecha_envio , fecha_contrato FROM contrato WHERE id_usuario LIKE '{$this->ID_USER}'"; } else { $this->QUERY = "SELECT id_contrato , nombre , contrato , " . "aceptado , fecha_envio , fecha_contrato FROM contrato WHERE id_usuario LIKE '{$id_user}'"; } $result = parent::RawQuery($this->QUERY); foreach ($result as $key => $value) { $extension = $directory->Get_Extension($value['contrato']); $datafile = FileExtension::GetIcon_extension($dir, $extension, $value['contrato']); if ($datafile != false) { $contract_array[] = array("id" => $value['id_contrato'], "nombre" => $value['nombre'], "contrato" => $value['contrato'], "aceptado" => $value['aceptado'], "fecha_envio" => $value['fecha_envio'], "fecha_contrato" => $value['fecha_contrato'], "icono" => $datafile); } else { $contract_array[] = array("id" => $value['id_contrato'], "nombre" => $value['nombre'], "contrato" => $value['contrato'], "aceptado" => $value['aceptado'], "fecha_envio" => $value['fecha_envio'], "fecha_contrato" => $value['fecha_contrato'], "icono" => "DocBroken.png"); } } return $contract_array; }
protected function beforeSave() { if (empty($this->id_file_type)) { $this->id_file_type = FileExtension::getTypeByExt($this->getExtension()); } $this->resizeImage(); return parent::beforeSave(); }