type = "photo"; $photo->title = $title; $photo->description = $description; $photo->name = $name; $pi = pathinfo(basename($filename)); if (empty($pi["extension"])) { throw new Exception("@todo UNKNOWN_FILE_TYPE"); } while (ORM::Factory("item") ->where("parent_id", $parent_id) ->where("name", $photo->name) ->find()->id) { $photo->name = rand() . "." . $pi["extension"]; } $photo->add_to_parent($parent_id); copy($filename, $photo->path()); /** @todo: parameterize these values */ $image = Image::factory($filename); $image->resize(200, 140, Image::WIDTH)->save($photo->thumbnail_path()); $image->resize(800, 600, Image::WIDTH)->save($photo->resize_path()); return $photo; } }