Skip to content

C-gen/file-uploader

Repository files navigation

File Uploader

A simple file hosting service like 0x0.st built with Laravel 12.

Features

  • ✅ File upload via HTTP POST
  • ✅ Automatic file expiration (24 hours for files ≤512KB, then decreases)
  • ✅ Direct download links
  • ✅ Manual deletion via token
  • ✅ Support for all file types
  • ✅ Maximum file size: 100MB

Quick Start

Using Docker Compose (Recommended)

  1. Clone the repository
  2. Run the setup script:
./setup.sh

This will automatically:

  • Create the .env file
  • Start Docker containers
  • Install dependencies
  • Generate application key
  • Run database migrations
  • Set proper permissions
  1. Access the application at http://localhost:8000

Manual Setup

If you prefer manual setup:

Manual Setup

  1. Install dependencies:
composer install
  1. Copy environment file:
cp env.example .env
  1. Generate application key:
php artisan key:generate
  1. Create SQLite database:
touch database/database.sqlite
  1. Run migrations:
php artisan migrate
  1. Start the development server:
php artisan serve

Usage

Upload a file

curl -F "file=@your_file.txt" http://localhost:8000

Response:

HTTP/1.1 200 OK
X-Delete: http://localhost:8000/delete/abc123def456...
Content-Type: text/plain

http://localhost:8000/file/xyz789abc123.txt

Download a file

curl http://localhost:8000/file/xyz789abc123.txt

Delete a file

curl http://localhost:8000/delete/abc123def456...

File Expiration

Files are automatically deleted based on their size:

  • Files ≤512KB: 24 hours
  • Larger files: Decreasing time based on logarithmic formula

Cleanup

To manually clean up expired files:

docker-compose exec app php artisan files:cleanup

Or set up a cron job to run this command periodically.

Testing

Run the test script to verify everything works:

./test-example.sh

This will:

  1. Create a test file
  2. Upload it to the service
  3. Download it back
  4. Show the response and delete URL

API Endpoints

  • POST / - Upload a file
  • GET /file/{filename} - Download a file
  • GET /delete/{token} - Delete a file
  • GET / - View usage instructions

Development

The application uses:

  • Laravel 12
  • PHP 8.4
  • SQLite database
  • Nginx web server
  • Docker for containerization

Architecture

The application follows Laravel best practices:

  • Models: UploadedFile handles file metadata and expiration logic
  • Controllers: FileController manages upload, download, and deletion
  • Commands: CleanupExpiredFiles for automatic cleanup
  • Views: Simple HTML page with usage instructions
  • Database: SQLite with migrations for file tracking

License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published