getId() . "-" . hash("sha256", $image->getName()) . "-" . time() . "." . self::IMAGES_FORMAT; } public static function getAllLite($only_mine, LuticateUsersDbo $_user, $page = 0, $perPage = 20000000) { return ImagesDataAccess::getAllLite($only_mine, $_user, $page, $perPage); } public static function getRawById($image_id) { /** * @var $dbo ImagesDbo */ $dbo = self::getById($image_id); echo file_get_contents($dbo->getPath()); exit; } public static function upload(ImageUploadDbo $image, LuticateUsersDbo $_user) { $path = self::generateImagePath($image, $_user); $dbo = new ImagesDbo(); $dbo->setUserId($_user->getId()); $dbo->setPath($path); $dbo->setDate(Carbon::now()); $dbo->setName($image->getName()); if (is_null($dbo->getName()) || $dbo->getName() === "") { $dbo->setName(Carbon::now()->toW3cString()); } $image->getImage()->scaleImage(420, 420, true); $image->getImage()->setImageFormat(self::IMAGES_FORMAT); try { $image->getImage()->writeImage($path); return ImagesDataAccess::addId($dbo); } catch (Exception $e) { LuLog::log($e); try { unlink($path); } catch (Exception $e) { } abort(500, "Failed to save image"); } return null; } public static function del($image_id, LuticateUsersDbo $_user) { /** * @var $imageDbo ImagesDbo */ $imageDbo = self::getById($image_id); if ($imageDbo->getUserId() != $_user->getId()) { self::unauthorized("You do not own this image"); } self::deleteById($imageDbo->getId()); try { unlink($imageDbo->getPath()); } catch (Exception $e) { LuLog::log($e); } return true; } }