<?php
require("../snippets/autoload.php");

$request = new Request();
$request->Id = $utils->SanitizeString($_POST["Request"]);

if($_FILES["file"]["name"]==""){
    $response_request["type"] = "error";
    $response_request["title"] = _("Error presented");
    $response_request["content"] = _("We can't upload your image, please try again");
}else{
  $filePath = realpath($_FILES["file"]["tmp_name"]);
  $name = $utils->GenerateLongString(15).$utils->GetFileExtension($_FILES["file"]["name"]);

  if(move_uploaded_file( $filePath,  "../../uploads/docs/".$name)){
    $request->PathTraslated = $name;
    if($request->UpdateFilePath()) {
      $response_request["type"] = "success";
      $response_request["title"] = _("Successful process");
      $response_request["content"] = _("Your file was updated successfully!");
    }else {
      $response_request["type"] = "error";
      $response_request["title"] = _("Error presented");
      $response_request["content"] = _("We can't upload your file, please try again");
    }
  }else{
    $response_request["type"] = "error";
    $response_request["title"] = _("Error presented");
    $response_request["content"] = _("We can't upload your file, please try again");
  }
}
echo json_encode($response_request);