I'm rebuilding a site in Laravel to test out the framework. It has a frontend and handles requests from a legacy C# app.
The C# app downloads a number of files via GET requests. All of these serve up fine, except when I try to download a file with the .php extension (ie. file.php). The framework serves me up a very simple page instead of a download:
<body>File not found.</body>
Typically, if I request a file that doesn't exist, it serves an empty page (I know it should serve a error page instead, but I'm trying to keep this brief).
I run these requests through a controller that checks for the file's existence before download:
// Route
Route::controller(DownloadsController::class)->group(function () {
...
Route::get('/downloads/{directory}/{filename}', 'downloadSubDirectory');
...
});
// DownloadsController
public function download($filename)
{
return Http::DownloadFile('cloudconnect/'.$filename);
}
...
// In Http class
public static function DownloadFile($filePath, $diskName = 'public')
{
$storage = Storage::disk($diskName);
if($storage->exists($filePath))
return $storage->download($filePath);
return null;
}
I can get this to work if I make a directory in /public/ and serve the file there, but that seems to be counter to everything the framework is trying to achieve.
I'm guessing there's some regex at the beginning of the request that matches any .php file and tries to process it before passing it to the Router.
EDIT: I know that downloading a .php file instead of processing it is not 'good'. The only reason I'm trying to do this is to support this legacy app that downloads a .php file (which is actually just a .xml file). I can't change the behavior of this legacy app. I know this is bad practice. The way it was handled before was open access to the directory listing, so people could download whichever file they wanted - which I recognize is also bad practice.
I was just wondering if there was some way I could serve this file explicitly? Or to phrase it differently, is the only way to serve a static .php file (not a blade template) by placing it in the /public/ directory?