webCOMAND

web_launcher::serve_public_file()

Serve a file as a web response, including the Content-Type header based on the detected MIME-Type.

If no file is found at the specified request URL and the URL references a directory that contains an index.php or index.html file, they will be served, in that order of preference.

Prototype

void server_public_file(string $dir, string $request, string $file_dir)

Parameters

  • dir - Path to the base folder where files are served.
  • request - Request URL, such as '/folder/file.txt'.
  • file_dir - Optional subfolder (or subpath) under dir, to look in for the requested file.  If not specified, 'public' will be used.

Example

$base_dir = '/var/files/packages/package_name';
$request = '/';
$file_dir = 'public_html';
\io_comand_package\web_launcher::serve_public_file($base_dir, $request, $file_dir);