Joe Scotto Joe Scotto - 4 months ago 27
reST (reStructuredText) Question

Slim framework url as file path

I'm new to using Slim and am trying to create a simple file hosting site. I'm trying to set my current directory via the url using

. Is there a way where I can have a url such as:
where everything after
is interpreted as the current path? I currently have this code:

$app->get('/panel/{path}', function ($request, $response) {
$path = $request->getAttribute('path');

return $path;

The issue is that I'm only able to return the
when only one path is set, I.E.
. If I do something such as
it will return a not found error. Any help would be great. Thanks!


Assuming you are using the latest Slim v3, you can use placeholders to achieve your goal as per the documentation:

Look for unlimited optional params

$app->get('/news[/{params:.*}]', function ($request, $response, $args) {
    $params = explode('/', $request->getAttribute('params'));

    // $params is an array of all the optional segments

In your case it would be:

$app->get('/panel/{path:.*}', function ($request, $response) {
    $path = $request->getAttribute('path');

    return $path;