I'm using CakePHP 3.x+.
I have created a library class to download youtube videos using youtube-dl
and return local URL of the file.
APP/src/Library/AnujTools/YoutubeDownload.php
<?php
namespace App\Library\AnujTools;
use Cake\Routing\Router;
class YoutubeDownload
{
public function download()
{
$user_upload_dir = 'files/youtube-video/123/';
$file_name = '324354554.mp4'
//
// download script here
//
$url = Router::url('/', true) . $user_upload_dir . $file_name;
return $url;
}
}
The file is downloaded to location
WWW_ROOT . 'files/youtube-video/123/324354554.mp4';
and return
statement must return
https://example.com/files/youtube-video/123/324354554.mp4
But it returns only
files/youtube-video/123/324354554.mp4
Debugging debug(Router::url('/', true));
gives only /