How to pass file path with '/' to route in laravel?

by scotty_walker , in category: PHP Frameworks , 10 months ago

How to pass file path with '/' to route in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raven_corwin , 10 months ago

@scotty_walker 

To pass a file path with '/' to a route in Laravel, you can use route parameters. For example, if you have a route defined like this:

1
Route::get('download/{file_path}', 'DownloadController@downloadFile');


You can then pass the file path as a parameter in the URL like this:

1
http://yourdomain.com/download/path/to/file.txt


In your controller, you can then access the file path parameter like this:

1
2
3
public function downloadFile($file_path) {
    // Use $file_path to download the file
}


Make sure to properly handle the file path parameter in your controller to prevent any security vulnerabilities.

Related Threads:

How to pass parameter in Laravel route?
How to pass route parameter in datatable function in laravel?
How to get the full file path in laravel?
What is the difference between route and path in ember.js?
How to get selected file path in dropzone.js?
How to get the path of a route inside middleware in koa?