Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created December 15, 2015 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hailwood/758fa432b040d0044e4c to your computer and use it in GitHub Desktop.
Save hailwood/758fa432b040d0044e4c to your computer and use it in GitHub Desktop.
<?php
//...
//Upload the new file
$upload = new Upload();
$upload->load($_FILES[$file['key']], "Form-Submissions/Form-One/{$sub->ID}");
//Retrieve the File Object
$newFile = $upload->getFile();
//We need to fetch the new file again otherwise things go wonky when we move the file...
/** @var File $newFileClass */
$newFileClass = get_class($newFile);
/** @var File $newFile */
$newFile = $newFileClass::get_by_id($newFileClass, $newFile->ID);
//Now we can move the new instance of the file
$newFile->setName($file['file'] . '.' . $newFile->getExtension());
$newFile->Title = $file['title'];
$newFile->write();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment