Skip to content

CakePHP Integration

Ankit Pokhrel edited this page Nov 23, 2020 · 6 revisions

Tus Server

  1. Add ankitpokhrel/tus-php as your dependency.

    $ composer require ankitpokhrel/tus-php
  2. Create a controller, say TusController.php or you can also use existing controller.

    <?php
    
    namespace App\Controller;
    
    use Cake\Controller\Controller;
    use TusPhp\Tus\Server as TusServer;
    use Symfony\Component\HttpFoundation\Response as HttpResponse;
    
    class TusController extends Controller
    {
        /**
         * Create tus server.
         *
         * @return HttpResponse
         */
        public function server()
        {
            $server = new TusServer('redis');
    
            $server
                ->setApiPath('/tus') // tus server endpoint.
                ->setUploadDir(WWW_ROOT . 'uploads'); // uploads dir, make sure it exists and is accessible.
    
            return $server->serve();
        }
    }
  3. Add a route to serve the request.

    // config/routes.php
    
    $routes->connect('/tus/*', ['controller' => 'Tus', 'action' => 'server']);

    You can now access tus server endpoints at http://yourapp.dev/tus or http://yourapp.dev/tus/.

Clone this wiki locally