为您的 Flarum 论坛提供极其智能的文件上传扩展。
An extension that handles file uploads intelligently for your forum.
Install manually:
composer require fof/upload:"*"composer require fof/upload:"*"
php flarum migrate
php flarum cache:clearEnable 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:
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.
Each mime type row can be given an optional Permission label (e.g. Images, Videos, Documents). When a label is set, FoF Upload automatically:
Upload Images — scoped to the Start section.Upload files permission and the mime-specific permission to upload that file type.Use cases:
How to configure:
Images).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:
bottom-right).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
0to restore the previous flush-edge behaviour.
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.
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.
| 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. |
thumbnail_path stored. The formatter falls back to the original full-resolution URL — no change in appearance.FoF Upload supports configuration via both the admin panel (database settings) and environment variables. Environment variables take precedence over database settings when configured.
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.
# 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:
php flarum cache:clearThe new service then appears under Admin → Upload → Storage, where you pick your provider and enter its credentials.
You can configure storage adapters using environment variables, which is particularly useful for:
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:
# 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.comWhen 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:
KEY, SECRET, BUCKET, REGION) must be setBUCKET, REGION, and USE_IAM=true are requiredLocalStack (local development):
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):
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:
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.comWasabi:
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.comBackblaze B2:
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.comFor local storage with a CDN in front:
FOF_UPLOAD_CDN_URL=https://cdn.example.comRegular 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,或尚未同步最近议题。