Responsive File Manager running on .NET Core with Peachpie
If you are not already using Peachpie for anything, then including Responsive File Manager is very easy:
-
Get the ResponsiveFileManager.AspNetCore NuGet package from: https://www.nuget.org/packages/ResponsiveFileManager.AspNetCore/
-
Add the following to your appsettings.json:
"ResponsiveFileManagerOptions": {
// Path from base_url to base of upload folder. Use start and final /
"UploadDirectory": "/Media/Uploads/",
// Relative path from filemanager folder to upload folder. Use final /
"CurrentPath": "../Media/Uploads/",
// Relative path from filemanager folder to thumbs folder. Use final / and DO NOT put inside upload folder.
"ThumbsBasePath": "../Media/Thumbs/",
"MaxSizeUpload": 10
}
More options can be found in the demo app.
- Add ResponsiveFileManager as middleware:
app.UseResponsiveFileManager();
- Optionally configure ResponsiveFileManager settings:
builder.Services.AddResponsiveFileManager(options =>
{
options.MaxSizeUpload = 32;
//etc
});
If you are wanting to use Peachpie for more than just ResponsiveFileManager, then it is recommended you ignore the ResponsiveFileManager.AspNetCore package, only acquire the base ResponsiveFileManager package and then manually configure the settings as follows:
-
Get the ResponsiveFileManager NuGet package from: https://www.nuget.org/packages/ResponsiveFileManager/
-
Copy the ResponsiveFileManagerOptions class from the ResponsiveFileManager.AspNetCore package into your project.
-
Add the following to your appsettings.json:
"ResponsiveFileManagerOptions": {
// Path from base_url to base of upload folder. Use start and final /
"UploadDirectory": "/Media/Uploads/",
// Relative path from filemanager folder to upload folder. Use final /
"CurrentPath": "../Media/Uploads/",
// Relative path from filemanager folder to thumbs folder. Use final / and DO NOT put inside upload folder.
"ThumbsBasePath": "../Media/Thumbs/",
"MaxSizeUpload": 10
}
More options can be found in the demo app.
- Open your
Program.cs
and ensure it looks something like this:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
});
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddResponsiveFileManager(options => options.MaxSizeUpload = 32);
var app = builder.Build();
app.UseSession();
app.UseDefaultFiles();
app.UseStaticFiles();
const string filemanagerPath = "/filemanager";
app.UseStaticFiles(new StaticFileOptions
{
RequestPath = filemanagerPath,
FileProvider = new PhysicalFileProvider(Path.GetFullPath(Path.Combine(Assembly.GetEntryAssembly().Location, ".." + filemanagerPath))),
});
app.UsePhp(filemanagerPath, (Context ctx) =>
{
// construct the options
var options = new ResponsiveFileManagerOptions();
ctx.GetService<IConfiguration>().GetSection("ResponsiveFileManagerOptions").Bind(options);
ctx.GetService<IConfigureOptions<ResponsiveFileManagerOptions>>()?.Configure(options);
// pass the options object to PHP globals
ctx.Globals["rfm_options"] = PhpValue.FromClass(options); // this is how config in appsettings.json is passed to PHP
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
app.Run();
You can use the source code in this repo, as follows:
- Open the solution in Visual Studio or newer.
- Set the WebApplication project as the default, if it isn't already.
- restore libs in WebApplication folder:
dotnet tool install -g Microsoft.Web.LibraryManager.Cli
libman restore
- Run and test one of the demo pages
- Look at the
Program.cs
file for configuration to copy to your own project to use with the NuGet package.
If you find this project helpful, consider buying me a cup of coffee.
Crypto | Wallet Address |
---|---|
1EeDfbcqoEaz6bbcWsymwPbYv4uyEaZ3Lp | |
0x277552efd6ea9ca9052a249e781abf1719ea9414 | |
LRUP8hukWGXRrcPK6Tm7iUp9vPvnNNt3uz |