百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
U

upload

> 开发工具
开源

为您的 Flarum 论坛提供极其智能的文件上传扩展。

190 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

为您的 Flarum 论坛提供极其智能的文件上传扩展。

Upload by FriendsOfFlarum

An extension that handles file uploads intelligently for your forum.

Features

  • For images:
    • Auto watermarks with proportional scaling, opacity and padding controls.
    • Auto resizing.
    • Dimension storage (width × height) for JPEG, PNG, and GIF — prevents layout shifts when images lazy-load.
    • WebP thumbnail generation at upload time — reduces bandwidth; clicking the thumbnail opens the original in a new tab.
    • Animated GIF support for resize operations.
  • Mime type to upload adapter mapping.
  • Whitelisting mime types.
  • Uploading on different storage services (local, imgur, AWS S3 for instance).
  • Drag and drop uploads.
  • Uploading multiple files at once (button and drag and drop both support this).
  • Easily extendable, the extension heavily relies on Events.
  • Extender interface to disable or force particular adapters (see below)

Installation

Install manually:

bash
composer require fof/upload:"*"

Updating

bash
composer require fof/upload:"*"
php flarum migrate
php flarum cache:clear

Configuration

Enable the extension, a new tab will appear on the left hand side. This separate settings page allows you to further configure the extension.

On new installations, a pre-defined regex will be inserted for you that enables image uploads, restricted to safe image types. We now include SVG as safe, due to our SVG sanitization method. Default image types allowed are:

  • JPEG
  • PNG
  • GIF
  • WebP
  • AVIF
  • BMP
  • TIFF
  • SVG

The regex for these types is ^image\/(jpeg|png|gif|webp|avif|bmp|tiff|svg\+xml)$, and can be modified as required. We STRONGLY discourage the use of a wildcard such as ^image\/.*, as this could introduce vulnerabilities in the uploaded files. Versions of fof/upload prior to 1.8.0 used this as default, and is considered insecure.

Make sure you configure the upload permission on the permissions page as well.

Per-Mime-Type Permission Scoping

Each mime type row can be given an optional Permission label (e.g. Images, Videos, Documents). When a label is set, FoF Upload automatically:

  1. Creates a dedicated permission in the Flarum permission grid — e.g. Upload Images — scoped to the Start section.
  2. Defaults that permission to the Member group on first use, preserving existing access.
  3. Enforces AND logic: a user must hold both the base Upload files permission and the mime-specific permission to upload that file type.

Use cases:

  • Allow Members to upload images but restrict video uploads to Staff.
  • Require a "Trusted" group role to upload ZIP archives or executable files.
  • Mix restricted and unrestricted types freely — mime types without a permission label require only the base upload permission (fully backwards-compatible).

How to configure:

  1. Go to Admin → Extensions → FoF Upload.
  2. In the Mime Types section, enter a label in the Permission label field for any type you want to restrict (e.g. Images).
  3. Save settings — the permission appears immediately in Admin → Permissions under the Start section.
  4. Adjust which groups have that permission as needed.

Watermark Configuration

When Watermark images is enabled, FoF Upload stamps every uploaded JPEG or PNG with a watermark image. Three settings let you control how the watermark looks:

Setting Default Description
Watermark size (% of image width) 25 The watermark is scaled so its width equals this percentage of the uploaded image's width. A value of 25 means the watermark will always be one-quarter the width of the image, regardless of upload dimensions.
Watermark opacity (0–100) 100 Opacity of the placed watermark. 100 is fully opaque; 0 is invisible.
Padding from edge (px) 10 Inward pixel offset from the corner or edge set by the Position field. Set to 0 to place the watermark flush against the edge.

How to configure:

  1. Go to Admin → Extensions → FoF Upload.
  2. Enable Watermark images and upload your watermark file.
  3. Choose a Position (e.g. bottom-right).
  4. Adjust size %, opacity, and padding to taste.
  5. Save — the settings are applied to every new image upload.

Backwards compatibility: Existing installs that used watermarks before these settings were introduced will use the defaults on next upload: 25% width, 100% opacity, 10 px padding. Set padding to 0 to restore the previous flush-edge behaviour.

Image Dimensions & Layout Shift Prevention

FoF Upload automatically stores the width and height (in pixels) of every JPEG, PNG, and GIF processed at upload time. These are recorded after any resizing or EXIF orientation correction is applied, so they always reflect the final image as stored.

The stored dimensions are injected as width and height HTML attributes on the `` tag rendered by the Image Preview template. Modern browsers use these attributes to reserve the correct amount of layout space before the image has loaded, eliminating Cumulative Layout Shift (CLS) in threads that contain lazy-loaded images.

No configuration is required — this happens automatically for all new JPEG, PNG, and GIF uploads. Images uploaded before this feature was added will not have stored dimensions; they continue to render without width/height attributes and are unaffected.

GIF support: Animated GIF uploads now also benefit from the Resize images setting. Watermarks are intentionally not applied to GIFs to avoid palette quality degradation.

Image Thumbnails

FoF Upload can generate a downscaled thumbnail at upload time to significantly reduce bandwidth for large-image forums. The original file is always kept intact.

When enabled, the Image Preview template displays the thumbnail as the visible image and wraps it in a link to the original — clicking the image opens the full-resolution file in a new tab.

How it works

  1. After the image is processed (resize, watermark, orientation), a copy is scaled down to a configurable maximum width (default: 1000 px).
  2. The thumbnail is encoded as WebP by default (~30% smaller than JPEG at equivalent quality) or in the original format if WebP is disabled.
  3. The thumbnail is stored alongside the original in the same storage backend (Local, S3, Qiniu). Imgur uploads are excluded — Imgur manages its own thumbnails.
  4. The thumbnail path is stored in the database. The full URL is derived from the live storage hostname at render time (same as the main file URL), so CDN domain changes are reflected automatically without re-processing.

Settings

Setting Default Description
Generate thumbnails on upload On Master toggle. Disable to revert to full-resolution images in the Image Preview template.
Encode thumbnails as WebP On Use WebP encoding for the thumbnail. Disable to use the original image format (JPEG/PNG/GIF).
Thumbnail max width (px) 1000 Thumbnails are scaled down so neither dimension exceeds this value. Images smaller than this are not upscaled.

Backwards compatibility

  • Old posts: Existing posts have no thumbnail_path stored. The formatter falls back to the original full-resolution URL — no change in appearance.
  • Imgur uploads: Thumbnails are not generated (Imgur handles image hosting directly).
  • Private-shared files: Thumbnails are not generated for private files.

Storage Configuration

FoF Upload supports configuration via both the admin panel (database settings) and environment variables. Environment variables take precedence over database settings when configured.

Installing storage adapters

Local storage and Imgur work out of the box. S3 and Qiniu each need an extra package — until it is installed, the adapter does not appear in the admin panel at all.

bash
# Amazon S3, and S3-compatible services (Cloudflare R2, Backblaze B2,
# DigitalOcean Spaces, MinIO, …)
composer require league/flysystem-aws-s3-v3:"^3.0"

# Qiniu
composer require overtrue/flysystem-qiniu:"^3.0"

Run these from your Flarum directory, then clear the cache:

bash
php flarum cache:clear

The new service then appears under Admin → Upload → Storage, where you pick your provider and enter its credentials.

Environment Variable Configuration

You can configure storage adapters using environment variables, which is particularly useful for:

  • Docker/containerized deployments
  • CI/CD pipelines
  • Multi-environment setups (dev/staging/production)
  • Keeping credentials out of the database
AWS S3 / S3-Compatible Storage

To configure S3 via environment variables, set all four required variables:

…

IAM Role Authentication (EC2/ECS/EKS):

For environments with IAM roles (EC2 instances, ECS tasks, EKS pods), you can omit credentials:

bash
# Required for IAM mode
FOF_UPLOAD_AWS_S3_BUCKET=your-bucket-name
FOF_UPLOAD_AWS_S3_REGION=us-east-1
FOF_UPLOAD_AWS_S3_USE_IAM=true  # Enable IAM role authentication

# Optional (same as above)
FOF_UPLOAD_AWS_S3_ACL=public-read
FOF_UPLOAD_CDN_URL=https://cdn.example.com

When FOF_UPLOAD_AWS_S3_USE_IAM=true, credentials are not required and the AWS SDK will automatically use the instance/pod IAM role.

Important Notes:

  • Traditional mode: All 4 variables (KEY, SECRET, BUCKET, REGION) must be set
  • IAM mode: Only BUCKET, REGION, and USE_IAM=true are required
  • If any required variable is missing, the extension falls back to database settings
  • Environment variables always override database settings when fully configured
S3-Compatible Services

LocalStack (local development):

bash
FOF_UPLOAD_AWS_S3_KEY=test
FOF_UPLOAD_AWS_S3_SECRET=test
FOF_UPLOAD_AWS_S3_BUCKET=uploads
FOF_UPLOAD_AWS_S3_REGION=us-east-1
FOF_UPLOAD_AWS_S3_ENDPOINT=http://localhost:4566
FOF_UPLOAD_AWS_S3_PATH_STYLE_ENDPOINT=true  # Required for LocalStack!

MinIO (self-hosted):

bash
FOF_UPLOAD_AWS_S3_KEY=minioadmin
FOF_UPLOAD_AWS_S3_SECRET=minioadmin
FOF_UPLOAD_AWS_S3_BUCKET=uploads
FOF_UPLOAD_AWS_S3_REGION=us-east-1
FOF_UPLOAD_AWS_S3_ENDPOINT=https://minio.example.com
FOF_UPLOAD_AWS_S3_PATH_STYLE_ENDPOINT=true  # Required for MinIO!

DigitalOcean Spaces:

bash
FOF_UPLOAD_AWS_S3_KEY=your-spaces-key
FOF_UPLOAD_AWS_S3_SECRET=your-spaces-secret
FOF_UPLOAD_AWS_S3_BUCKET=your-space-name
FOF_UPLOAD_AWS_S3_REGION=nyc3
FOF_UPLOAD_AWS_S3_ENDPOINT=https://nyc3.digitaloceanspaces.com

Wasabi:

bash
FOF_UPLOAD_AWS_S3_KEY=your-wasabi-key
FOF_UPLOAD_AWS_S3_SECRET=your-wasabi-secret
FOF_UPLOAD_AWS_S3_BUCKET=your-bucket
FOF_UPLOAD_AWS_S3_REGION=us-east-1
FOF_UPLOAD_AWS_S3_ENDPOINT=https://s3.wasabisys.com

Backblaze B2:

bash
FOF_UPLOAD_AWS_S3_KEY=your-key-id
FOF_UPLOAD_AWS_S3_SECRET=your-application-key
FOF_UPLOAD_AWS_S3_BUCKET=your-bucket
FOF_UPLOAD_AWS_S3_REGION=us-west-004
FOF_UPLOAD_AWS_S3_ENDPOINT=https://s3.us-west-004.backblazeb2.com
Local Storage with CDN

For local storage with a CDN in front:

bash
FOF_UPLOAD_CDN_URL=https://cdn.example.com

Configuration Priority

  1. Environment Variables (highest priority - when all required vars are set)
  2. Database Settings (admin panel configuration)
  3. Defaults (null values if neither is configured)

Mimetype regular expression

Regular expressions allow you a lot of freedom, but they are also very difficult to understand. Here are some pointers, but feel free to ask for help on the official Flarum forums, or check out regex101.com where you can interactively build and test your regex pattern.

In case you want to allow all regular file types including video, music, compressed files and images, use this:

(video\/(3gpp|mp

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPclipboarddrag-and-dropflagrowflarum

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具