type = "photo"; $photo->title = $title; $photo->description = $description; $photo->name = $name; $photo->owner_id = $owner_id; $photo->width = $image_info[0]; $photo->height = $image_info[1]; $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; // Randomize the name if there's a conflict while (ORM::Factory("item") ->where("parent_id", $parent_id) ->where("name", $photo->name) ->find()->id) { // @todo Improve this. Random numbers are not user friendly $photo->name = rand() . "." . $pi["extension"]; } // This saves the photo $photo->add_to_parent($parent_id); copy($filename, $photo->file_path()); // @todo: parameterize these dimensions // This saves the photo a second time, which is unfortunate but difficult to avoid. return $photo->set_thumbnail($filename, 200, 140) ->set_resize($filename, 800, 600) ->save(); } }