<?php require_once __DIR__ . '/../app/lib/File.php'; try { $err = File::getError(); if ($err) { throw new Exception($err); } if (File::getSize() > 512000) { throw new Exception('File is too large'); } $tmp_name = File::getTmpName(); $newName = '/uploads/' . time() . '_' . File::getOriginalName(); if (!move_uploaded_file($tmp_name, __DIR__ . $newName)) { throw new Exception('Unable move file in the server'); } echo json_encode(array('path' => $newName)); } catch (Exception $e) { http_response_code(412); echo json_encode(array('error' => array('Message' => $e->getMessage()))); }