Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Vimo's avatar
Level 4

Retrieve php file from storage

I am attempting to retrieve a .php file from the storage. The file is located in public/storage/. However, I am getting a 404.

HTML files and other extensions work, but not .php.

Calling http://foobar.dew/storage/index.php in the browser doesn't work but http://foobar.dew/storage/index.html works.

Is there any way to be able to retrieve PHP files from the storage?

Thanks in advance!

0 likes
4 replies
guybrush_threepwood's avatar
Level 33

Could you explain why you want to serve PHP files from the public folder?

Are the PHP files uploaded by the user or user-generated?

Are you attempting to render the PHP file or do you just want to serve the raw data as text?

Laravel's public/.htaccess redirects all PHP file requests to public/index.php by design. The framework is supposed to have a single entry point for all requests.

Vimo's avatar
Level 4

The files are only used by me. I am uploading them to easily be able to download them using a visual list.

I am attempting to serve the data as text. Tried using file_get_contents() with the given path which returns 404. Maybe it’s better to use another extension

guybrush_threepwood's avatar

You could create a controller in order to stream the file as plain text (untested code):

public function stream($fileName)
{
    $fullPath = public_path('storage/' . $fileName);

    return response()->file($fullPath, ['Content-Type' => 'text/plain']);
}

Be careful that the end user doesn't end up requesting an unauthorized file.

Vimo's avatar
Level 4

I will try this. Thanks!

1 like

Please or to participate in this conversation.