/go-filemanager

🗂️ Modern web-based file manager built with Go. Features file preview, UTF-8 support, responsive design, and secure file operations.

Primary LanguageGo

Go Web File Manager

A simple, web-based file manager application built with Go that allows you to manage files and folders through a web interface.

Features

  • 📁 Browse directories - Navigate through folders with breadcrumb navigation
  • 📤 Upload files - Upload files to any directory
  • 📥 Download files - Download files directly from the web interface
  • 📁 Create folders - Create new directories
  • 🗑️ Delete files/folders - Remove files and directories
  • 🔒 Security - Path traversal protection to keep files within the designated directory
  • 📱 Responsive design - Works on desktop and mobile devices

Installation & Usage

  1. Prerequisites: Make sure you have Go installed (Go 1.21 or later)

  2. Clone or download the project files

  3. Run the application:

    go run main.go
  4. Access the file manager: Open your web browser and go to http://localhost:8080

File Structure

filemanager/
├── main.go          # Main application file
├── go.mod           # Go module file
├── README.md        # This file
└── files/           # Root directory for file management (created automatically)

How to Use

Navigation

  • Click on folder names to enter directories
  • Use the "⬆️ Up" button to go to the parent directory
  • Use breadcrumb navigation to jump to any parent directory

File Operations

  • Upload File: Click "📤 Upload File" button, select a file, and click "Upload"
  • Download File: Click the "📥 Download" button next to any file
  • Delete: Click the "🗑️ Delete" button next to any file or folder (confirmation required)

Folder Operations

  • Create Folder: Click "📁 New Folder" button, enter a name, and click "Create"
  • Navigate: Click on any folder name to enter it

Configuration

Change Root Directory

By default, files are managed in the ./files directory. To change this, modify the rootDir variable in main.go:

rootDir = "/path/to/your/directory"

Change Port

To run on a different port, modify the port in the ListenAndServe call:

log.Fatal(http.ListenAndServe(":3000", nil))  // Changes port to 3000

Security Features

  • Path Traversal Protection: Prevents access to files outside the designated root directory
  • Safe File Operations: All file operations are validated to ensure they stay within bounds
  • Input Validation: Form inputs are validated before processing

API Endpoints

  • GET / - Main file browser interface
  • POST /upload - Upload files
  • GET /download - Download files
  • POST /mkdir - Create directories
  • POST /delete - Delete files/directories

Browser Compatibility

This application works with all modern web browsers including:

  • Chrome/Chromium
  • Firefox
  • Safari
  • Edge

Development

The application is built with:

  • Backend: Go (standard library only)
  • Frontend: HTML5, CSS3, JavaScript (vanilla)
  • Styling: Custom CSS with responsive design

Troubleshooting

Common Issues

  1. Permission Denied: Make sure the application has read/write permissions to the files directory
  2. Port Already in Use: Change the port number in main.go if port 8080 is already occupied
  3. File Upload Issues: Check that the files directory exists and is writable

Error Messages

  • "Access denied" - Attempting to access files outside the root directory
  • "Failed to read directory" - Directory doesn't exist or no read permissions
  • "Failed to create file" - No write permissions or disk space issues

License

This project is open source and available under the MIT License.