PHP Classes

File: public/copy.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Asynchronous Long Server Tasks   public/copy.php   Download  
File: public/copy.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Asynchronous Long Server Tasks
Start background tasks and query progress status
Author: By
Last change: fixing mandatory parameters
Date: 8 years ago
Size: 872 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
JLaso\ToolsLib\Json;
use
JLaso\ToolsLib\Starter;

$id = isset($_REQUEST["id"]) ? intval($_REQUEST["id"]) : null;
$file = $_REQUEST["file"];
$task = $_REQUEST["_task"];

if ((
null === $id) || !is_array($file) || !$task) {

   
Json::error('The "id","file" and "_task" are mandatory in order to process your request!');

} else {
   
$url = ($_SERVER["SERVER_PORT"] == "443") ? "https://" : "http://";
   
$url .= $_SERVER["SERVER_NAME"] . "/server/copy-file.php";
   
$starter = new Starter($url, $task);

    if (
Starter::SUCCESS == ($result = $starter->invoke(array("id" => $id, "name" => $file["name"], "size" => $file["size"])))) {
       
Json::ok(array('id' => $id));
    } else {
       
Json::error('something wrong happened trying to start the task on the server! '.$starter->getLastError());
    }

}