@unlink($filepath);
}
+ public function getFile()
+ {
+ if (!$this->fileRecord instanceof File) {
+ throw new ServerException('File record did not exist for MediaFile');
+ }
+
+ return $this->fileRecord;
+ }
+
protected function storeFile()
{
{
$file_redir = File_redirection::getKV('url', $url);
- if ($file_redir instanceof File_redirection) {
+ if (!$file_redir instanceof File_redirection) {
$file_redir = new File_redirection;
$file_redir->url = $url;
$file_redir->file_id = $file_id;
}
}
- static function fromUpload($param = 'media', Profile $scoped)
+ static function fromUpload($param='media', Profile $scoped=null)
{
if (is_null($scoped)) {
$scoped = Profile::current();
}
- if (!isset($_FILES[$param]['error'])){
- return;
+ // The existence of the "error" element means PHP has processed it properly even if it was ok.
+ if (!isset($_FILES[$param]) || !isset($_FILES[$param]['error'])) {
+ throw new NoUploadedMediaException($param);
}
switch ($_FILES[$param]['error']) {
' partially uploaded.'));
case UPLOAD_ERR_NO_FILE:
// No file; probably just a non-AJAX submission.
- return;
+ throw new NoUploadedMediaException($param);
case UPLOAD_ERR_NO_TMP_DIR:
// TRANS: Client exception thrown when a temporary folder is not present to store a file upload.
throw new ClientException(_('Missing a temporary folder.'));