Parcourir la source

Attachment upload in Docker

svalavuo il y a 1 jour
Parent
commit
c2819b6136
5 fichiers modifiés avec 15 ajouts et 7 suppressions
  1. 4 4
      Dockerfile
  2. 1 1
      backend/api/upload.php
  3. 1 1
      backend/models/Attachment.php
  4. 7 1
      build.sh
  5. 2 0
      docker-compose.yml

+ 4 - 4
Dockerfile

@@ -57,10 +57,10 @@ COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
 # Copy test script for environment testing
 COPY test-env.php ./
 
-# Create uploads directory and set permissions
-RUN mkdir -p uploads && \
-    chown -R www-data:www-data /var/www/html/uploads && \
-    chmod -R 755 /var/www/html/uploads
+# Create uploads and attachments directories and set permissions
+RUN mkdir -p uploads attachments && \
+    chown -R www-data:www-data /var/www/html/uploads /var/www/html/attachments && \
+    chmod -R 755 /var/www/html/uploads /var/www/html/attachments
 
 # Copy Apache configuration
 COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf

+ 1 - 1
backend/api/upload.php

@@ -20,7 +20,7 @@ if (!isset($_FILES['picture']) || $_FILES['picture']['error'] !== UPLOAD_ERR_OK)
     exit;
 }
 
-$uploadDir = 'uploads/';
+$uploadDir = '/var/www/html/uploads/';
 $allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
 $maxFileSize = 5 * 1024 * 1024; // 5MB
 

+ 1 - 1
backend/models/Attachment.php

@@ -99,7 +99,7 @@ class Attachment {
     }
 
     public function uploadFile($file, $item_id, $file_type) {
-        $uploadDir = 'attachments/';
+        $uploadDir = '/var/www/html/attachments/';
         $allowedTypes = [
             'application/pdf',
             'image/jpeg',

+ 7 - 1
build.sh

@@ -75,13 +75,19 @@ if [ -z "$DB_PASS" ] || [ "$DB_PASS" = "your-db-password" ]; then
     exit 1
 fi
 
-# Create uploads directory if it doesn't exist
+# Create uploads and attachments directories if they don't exist
 if [ ! -d uploads ]; then
     echo "📁 Creating uploads directory..."
     mkdir -p uploads
     chmod 755 uploads
 fi
 
+if [ ! -d attachments ]; then
+    echo "📁 Creating attachments directory..."
+    mkdir -p attachments
+    chmod 755 attachments
+fi
+
 # Copy .env to backend/.env.local for PHP application
 echo "📝 Copying environment variables to backend/.env.local..."
 if [ -f .env ]; then

+ 2 - 0
docker-compose.yml

@@ -27,6 +27,8 @@ services:
       - ALLOWED_FILE_TYPES=${ALLOWED_FILE_TYPES:-pdf,doc,docx,xls,xlsx,jpg,jpeg,png,gif}
     volumes:
       - uploads_data:/var/www/html/uploads
+      - ./uploads:/var/www/html/uploads
+      - ./attachments:/var/www/html/attachments
     restart: unless-stopped
     healthcheck:
       test: ["CMD", "curl", "-f", "http://localhost/api/company.php"]