Created
May 27, 2009 08:53
-
-
Save hugowetterberg/118529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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