PHP Classes

File: public/copy-multi.php

Recommend this page to a friend!
  Classes of Joseluis Laso  >  Asynchronous Long Server Tasks  >  public/copy-multi.php  >  Download  
File: public/copy-multi.php
Role: Example script
Content type: text/plain
Description: new example third part
Class: Asynchronous Long Server Tasks
Start background tasks and query progress status
Author: By
Last change:
Date: 6 years ago
Size: 889 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-multi.php";
   
$starter = new Starter($url, $task."-".$id);

    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());
    }

}

For more information send a message to info at phpclasses dot org.