Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created May 27, 2009 08:53
Show Gist options
  • Save hugowetterberg/118529 to your computer and use it in GitHub Desktop.
Save hugowetterberg/118529 to your computer and use it in GitHub Desktop.
<?php
if (!empty($_FILES['file'])) {
$file = $_FILES['file'];
$result = $rest->post($oa->resourceUri("image"), array(
'title' => $formData['upload_title'],
'license' => array($formData['license'] => TRUE),
));
try {
// Move the uploaded file so that we get a proper name
mkdir($dir = $file['tmp_name'] . '_dir');
$destination = $dir . '/' . $file['name'];
move_uploaded_file($file['tmp_name'], $destination);
// Post the file
$rest->postFile($oa->resourceUri("image/{$result->nid}/file"),
$destination, $file['type']);
// Set url and title
$formData['title'] = $formData['upload_title'];
$formData['uri'] = $result->url;
}
catch (Exception $e) {
$rest->delete($oa->resourceUri("image/{$result->nid}"));
throw $e;
}
}
unset($formData['upload_title'], $formData['submit']);
$rest->post($oa->resourceUri("{$resource}/{$nid}/link"), $formData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment