$plugin_project->save();
// Extract file and save to default filestore (for now)
$prefix = "plugins/";
$filestorename = $prefix . strtolower(time() . $_FILES['upload']['name']);
$release = new PluginRelease();
$release->title = $plugin_project->title;
$release->setFilename($filestorename);
$release->setMimetype($mimetype);
$release->originalfilename = $_FILES['upload']['name'];
$release->access_id = $release_access_id;
$release->container_guid = $plugin_project->getGUID();
$release->version = $version;
$release->release_notes = $release_notes;
$release->elgg_version = $elgg_version;
$release->comments = $comments;
$release->save();
if ($release->savePluginFile('upload') != TRUE) {
    register_error(elgg_echo("plugins:error:uploadfailed"));
    forward(REFERER);
}
if (!$plugin_project->getGUID() || !$release->getGUID()) {
    register_error(elgg_echo("plugins:error:uploadfailed"));
    forward(REFERER);
}
if ($recommended == 'yes') {
    $plugin_project->recommended_release_guid = $release->getGUID();
}
// check for any project images and associate them with the project
$max_num_images = 4;
for ($i = 1; $i <= $max_num_images; $i++) {
    if (!array_key_exists("image_{$i}", $_FILES)) {
    forward(REFERER);
}
// Extract file and save to default filestore (for now)
$prefix = "plugins/";
$filestorename = $prefix . strtolower(time() . $_FILES['upload']['name']);
$release = new PluginRelease();
$release->title = $plugin_project->title;
$release->setFilename($filestorename);
$release->setMimetype($mimetype);
$release->originalfilename = $_FILES['upload']['name'];
$release->access_id = $access_id;
$release->container_guid = $plugin_project->getGUID();
$release->version = $version;
$release->release_notes = $release_notes;
$release->elgg_version = $elgg_version;
$release->comments = $comments;
if (!$release->save()) {
    register_error(elgg_echo("plugins:error:uploadfailed"));
    forward($plugin_project->getURL());
}
if ($release->savePluginFile('upload') != TRUE) {
    register_error(elgg_echo("plugins:error:uploadfailed"));
    forward(REFERER);
}
if ($recommended == 'yes') {
    $plugin_project->recommended_release_guid = $release->getGUID();
}
add_to_river('river/object/plugin_release/create', 'create', get_loggedin_userid(), $release->guid);
plugins_send_notifications($release);
system_message(elgg_echo("plugins:release:saved"));
forward($release->getURL());