An image uploader. Written in PHP, supports popular formats: png, jpeg, gif, webp.
Lets you upload multiple images in a row and see them all in one view. Generates a permalink and lets you copy it right away. No bullshit steps along the way.
Uploaded image is verified and re-created from its contents to provide some layer of security against exploits.
PHP 8.5 | Composer | jQuery | Twig | KEYS.css by Michael Hüneburg
For production, check out a release tag instead of main (git checkout <tag>).
git clone https://github.com/c0m4r/up.git
cd up
# Edit config.php first: set allowed_hosts to your domain (include the port if it is not 80/443)
docker compose up -d --buildThe uploader listens on port 8080; put it behind a TLS-terminating reverse proxy (ssl in config.php controls whether generated links use https).
What you get:
- Images are built locally from the official
php(8.5.12, FPM, Alpine) andnginximages, pinned by digest. - Composer dependencies are installed at build time from
composer.lock, with plugins and scripts disabled. Nothing needs to be downloaded or run on the host. - PHP-FPM runs as
www-data, both containers have a read-only root filesystem, drop all unneeded capabilities and setno-new-privileges. - Uploads and logs live in the
uploadsandlogsnamed volumes, e.g.docker compose exec php-fpm tail logs/uploads.log.
To update, pull the new version and rebuild: git pull && docker compose up -d --build.
Variants are available as override files:
# IPv6 network
docker compose -f docker-compose.yml -f .docker/docker-compose.ipv6.yml up -d --build
# paranoya malware scanner, see the paranoya integration section below
docker compose -f docker-compose.yml -f .docker/docker-compose-with-paranoya.yml up -d --build- PHP 8.5.12 or newer
- Required extensions:
ctype,exif,fileinfo,gd(with JPEG, PNG and WebP support) andmbstring. - Optional:
socketsfor the paranoya integration. - Running
composer.pharneedsopensslandpharas well. - Set
upload_max_filesize = 10Mandpost_max_size = 11M(see .docker/php/up.ini).
- Required extensions:
- Nginx: set client_max_body_size to
11M. .docker/nginx contains a configuration that only exposes the public files. - The web server or PHP-FPM user must have write access to
iandlogs.
git clone https://github.com/c0m4r/up.git
cd up
# Download Composer and verify it against the checksum pinned here before running it
curl -fsSLO https://getcomposer.org/download/2.11.1/composer.phar
echo "6f1b891e1d4927d62740276c540fb490e47689e19e102c49e8da849794882f8c composer.phar" | sha256sum --check --strict || rm -f composer.phar
# Install exactly what composer.lock pins: no dev tools, no plugins, no scripts
php composer.phar install --no-dev --no-plugins --no-scripts --classmap-authoritative
php composer.phar audit --lockedThen:
- Disallow access to dot files, logs and other non-public files in the web server configuration (see .docker/nginx).
- Edit config.php, replace
allowed_hostswith your domain and adjust the settings to your needs. - Edit manifest.json and change
start_urlfor PWA.
Always use composer install to deploy. composer update ignores composer.lock and resolves the newest available versions, which is a job for development, not for a server.
- Dependencies: only Twig and jQuery (plus one tiny Symfony package Twig needs). Uploaded images are re-encoded with GD, without third-party image libraries.
- Composer:
composer.lockis the single source of truth. Plugins are disabled and the dependency policy refuses versions with security advisories, versions flagged as malware and abandoned packages. A 7-day cooldown keeps freshly published (possibly compromised) releases out ofcomposer update. - Containers: base images are pinned by tag and digest. Builds never fetch unpinned code.
- CI: GitHub Actions are pinned to commit SHAs, run with a read-only token and do not persist credentials. Workflows are audited with zizmor, and pull requests that add vulnerable dependencies fail the dependency review.
composer auditruns on every push and weekly. - Updates: Dependabot proposes Composer, Docker and GitHub Actions updates after the same 7-day cooldown. Security updates are not delayed.
The CI checks run in the same PHP image as production:
docker build --target dev -t up:dev .
docker run --rm up:dev composer validate --strict
docker run --rm up:dev composer audit --locked
docker run --rm up:dev vendor/bin/phpstan analysePHPStan runs at the maximum level with the strict and deprecation rules.
To update dependencies, run php composer.phar update and commit composer.lock. If a security fix is still inside the cooldown period, update just that package with php composer.phar update --no-cooldown vendor/package.
When bumping Composer, update the version and checksum above (from https://getcomposer.org/download/<version>/composer.phar.sha256sum). Dependabot keeps the composer image in the Dockerfile current, but not this README.
As an additional security measure you might want to scan uploaded files for malware.
See: paranoya integration (experimental)
With Docker, clone paranoya into the project directory, set "paranoya" => true and "paranoya_host" => 'paranoya' in config.php and start the stack with .docker/docker-compose-with-paranoya.yml (see above). PHP and the scanner share a dedicated volume for uploaded files instead of the host's /tmp.
- Animated WebP is not supported at this point
- Animated GIFs are limited to 1000 frames
MIT License
Copyright (c) 2023 c0m4r
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
If you found this software helpful, please consider making donation to a charity on my behalf. Thank you.