Filename=$id; $this->TempFile=$tempFile; $id=0; } parent::__construct("images", "image_id", $id); if ($this->ImageId) $this->CalculatePaths(); } private function CalculatePaths() { $dir=ApplicationSettings::GetSetting("images", "upload_location"); $info=pathinfo($this->ImageFilename); $this->Path=$dir.'/'.$this->ImageFilename; $this->ThumbnailPath=$dir.'/'.$info['filename'].'.thumbnail.'.$info['extension']; } private function MakeFileName() { return $this->ImageId."_".Utils::MakeStringUrlSafe($this->Filename); } public function Save() { $newSave=!$this->ImageId; parent::Save(); if ($newSave&&$this->ImageId) { $this->ImageFilename=$this->MakeFileName(); $this->CalculatePaths(); if (!move_uploaded_file($this->TempFile, $this->Path)) throw new Exception("Unable to move uploaded file: ".$this->Path.', '.$this->TempFile); if (class_exists("Imagick")) { $thumb=new Imagick($this->Path); $height=ApplicationSettings::GetSetting("images", "thumbnail_height"); $width=ApplicationSettings::GetSetting("images", "thumbnail_width"); $thumb->scaleImage(0, $height); $thumb->scaleImage($width, 0); $thumb->writeImage($this->ThumbnailPath); $thumb->clear(); $thumb->destroy(); } else copy($this->Path, $this->ThumbnailPath); parent::Save(); } } public function jsonSerialize() { $obj=parent::jsonSerialize(); $obj->ThumbnailPath=$this->ThumbnailPath; $obj->Path=$this->Path; return $obj; } }