123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class ApiMediaUploadAction extends ApiAuthAction
- {
- protected $needPost = true;
-
- protected function handle()
- {
- parent::handle();
-
-
- if (empty($_FILES)
- && empty($_POST)
- && ($_SERVER['CONTENT_LENGTH'] > 0)
- ) {
-
-
- $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.',
- 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
- intval($_SERVER['CONTENT_LENGTH']));
- $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
- }
-
- $upload = MediaFile::fromUpload('media', $this->scoped);
-
-
- $this->showResponse($upload);
- }
-
- function showResponse(MediaFile $upload)
- {
- $this->initDocument();
- $this->elementStart('rsp', array('stat' => 'ok'));
- $this->element('mediaid', null, $upload->fileRecord->id);
- $this->element('mediaurl', null, $upload->shortUrl());
- $this->elementEnd('rsp');
- $this->endDocument();
- }
-
- function clientError($msg)
- {
- $this->initDocument();
- $this->elementStart('rsp', array('stat' => 'fail'));
-
- $errAttr = array('msg' => $msg);
- $this->element('err', $errAttr, null);
- $this->elementEnd('rsp');
- $this->endDocument();
- }
- }
|