You are here

public function UploaderServlet::doPost in N1ED - Visual editor as CKEditor plugin with Bootstrap support 7

File

vendor/edsdk/file-uploader-server-php/src/servlet/UploaderServlet.php, line 85

Class

UploaderServlet

Namespace

EdSDK\FileUploaderServer\servlet

Code

public function doPost($post, $files) {
  $this
    ->addHeaders();
  $resp = null;
  $strResp = null;
  try {
    $req = null;
    try {
      $req = $this
        ->getReq($post, $files);
    } catch (Exception $e) {
      error_log($e);
    }
    if ($req === null) {
      $req = new ReqError(Message::createMessage(Message::MALFORMED_REQUEST));
    }
    $resp = $this->m_uploader
      ->run($req);
    if ($resp === null) {
      throw new Exception("Null response as result");
    }
    $strResp = $this->m_json
      ->toJson($resp);
  } catch (Exception $e) {
    error_log($e);
    $resp = new RespFail(Message::createMessage(Message::INTERNAL_ERROR));
    $strResp = $this->m_json
      ->toJson($resp);
  }
  try {
    http_response_code(200);
    header('Content-Type: application/json; charset=UTF-8');
    print $strResp;
  } catch (Exception $e) {
    error_log($e);
  }
}