Skip to content

gordon-matt/peachpie-responsive-file-manager

Repository files navigation

NuGet NuGet Donate

Peachpie Responsive File Manager

peachpie-responsive-file-manager

Responsive File Manager running on .NET Core with Peachpie

Getting Started

If you are not already using Peachpie for anything, then including Responsive File Manager is very easy:

  1. Get the ResponsiveFileManager.AspNetCore NuGet package from: https://www.nuget.org/packages/ResponsiveFileManager.AspNetCore/

  2. 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.

  1. Add ResponsiveFileManager as middleware:
app.UseResponsiveFileManager();
  1. 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:

  1. Get the ResponsiveFileManager NuGet package from: https://www.nuget.org/packages/ResponsiveFileManager/

  2. Copy the ResponsiveFileManagerOptions class from the ResponsiveFileManager.AspNetCore package into your project.

  3. 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.

  1. 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:

  1. Open the solution in Visual Studio or newer.
  2. Set the WebApplication project as the default, if it isn't already.
  3. restore libs in WebApplication folder:
  • dotnet tool install -g Microsoft.Web.LibraryManager.Cli
  • libman restore
  1. Run and test one of the demo pages
  2. Look at the Program.cs file for configuration to copy to your own project to use with the NuGet package.

Donate

If you find this project helpful, consider buying me a cup of coffee.

PayPal

Crypto Wallet Address
Bitcoin 1EeDfbcqoEaz6bbcWsymwPbYv4uyEaZ3Lp
Ethereum 0x277552efd6ea9ca9052a249e781abf1719ea9414
Litecoin LRUP8hukWGXRrcPK6Tm7iUp9vPvnNNt3uz

gordon-matt

About

Responsive File Manager running on .NET Core with Peachpie

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •