Compare commits

..

No commits in common. "f3febd737dde9bede0d4d751e5fb678f49e349cd" and "780ea18f5bf189320aea840ac4de5247dd270be8" have entirely different histories.

4 changed files with 39 additions and 33 deletions

@ -1,10 +1,12 @@
FROM alpine:3.18.2
FROM ubuntu:23.04
# Install dependencies
RUN apk update && \
apk upgrade && \
apk add --no-cache nginx php81 php81-fpm php81-gd && \
rm -rf /var/cache/apk/*
RUN apt update
RUN DEBIAN_FRONTEND=noninteractive \
apt install nginx php8.1 php8.1-fpm php8.1-gd php8.1-imagick -y
# Clean up
RUN apt clean
# Set up nginx
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
@ -14,4 +16,4 @@ COPY ./upload.php /tmp/upload.php
COPY ./docker/start.sh /start.sh
# Start server
CMD ["sh", "/start.sh"]
CMD ["bash", "/start.sh"]

@ -44,7 +44,7 @@ http {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php.sock;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;

@ -1,9 +1,5 @@
#!/bin/sh
# TODO: add all the other fallback values for the other variables
if [ -z "$MAX_UPLOAD_SIZE" ]; then
if [[ -z "${MAX_UPLOAD_SIZE}" ]]; then
MAX_UPLOAD_SIZE="8M" # Default fallback value
echo "MAX_UPLOAD_SIZE was not set, using default value of ${MAX_UPLOAD_SIZE}"
fi
echo "Checking if upload script exists in /var/www/html"
@ -15,15 +11,8 @@ else
fi
# Letting php know that we are running in docker
echo "env[DOCKER] = true" >> /etc/php81/php-fpm.d/www.conf
echo "clear_env = no" >> /etc/php81/php-fpm.d/www.conf
# Create the directory for PHP socket
mkdir -p /run/php
# Set php-fpm to listen on socket
touch /run/php/php.sock
sed -i 's/^listen = .*/listen = \/run\/php\/php.sock/' /etc/php81/php-fpm.d/www.conf
echo "env[DOCKER] = true" >> /etc/php/8.1/fpm/pool.d/www.conf
echo "clear_env = no" >> /etc/php/8.1/fpm/pool.d/www.conf
echo "Setting permissions for upload script"
chmod 777 /var/www/html/upload.php
@ -31,16 +20,16 @@ chmod 777 /var/www/html/upload.php
echo "Setting max upload size to ${MAX_UPLOAD_SIZE}"
# Set max upload size for php
sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php81/php.ini
sed -i "s/^upload_max_filesize = .*/upload_max_filesize = ${MAX_UPLOAD_SIZE}/" /etc/php/8.1/fpm/php.ini
sed -i "s/^post_max_size = .*/post_max_size = ${MAX_UPLOAD_SIZE}/" /etc/php/8.1/fpm/php.ini
# Set max upload size for nginx
sed -i "s/client_max_body_size 500M;/client_max_body_size ${MAX_UPLOAD_SIZE};/" /etc/nginx/nginx.conf
function start() {
echo "Starting PHP & Nginx"
php-fpm81 &&
chmod 777 /run/php/php.sock &&
/etc/init.d/php8.1-fpm start &&
chmod 777 /run/php/php8.1-fpm.sock &&
nginx -g 'daemon off;'
}

@ -162,13 +162,28 @@ try {
// Check the file type and size
if ($shouldConvertToWebp && in_array($fileType, ["png", "jpeg", "jpg"]) && $_FILES["sharex"]["size"] > $webpThreadhold) {
$image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"]));
// Create an Imagick object from the uploaded file
$image = new Imagick($_FILES["sharex"]["tmp_name"]);
// Convert the image to WebP
$image->setImageFormat("webp");
$image->setImageCompressionQuality($webpQuality);
// Set the output filename
$webp_file = pathinfo($finalName, PATHINFO_FILENAME) . ".webp";
imagewebp($image, $webp_file, 90); // Convert the image and save it
imagedestroy($image); // Free up memory
$finalName = $webp_file;
$shouldSave = false;
// Save the converted image
$image->writeImage($webp_file);
// Free up memory
$image->clear();
$image->destroy();
$fileSize = filesize($webp_file); // Update the file size
// Update the final filename
$finalName = $webp_file;
$needsToBeSaved = false;
}
if ($needsToBeSaved) { // Save the file if it has not been saved yet