From 15209afdccb15094a6bc1b72a52df331c80c5527 Mon Sep 17 00:00:00 2001
From: haidar <89732397+haidarhamda@users.noreply.github.com>
Date: Sun, 8 Oct 2023 15:55:31 +0700
Subject: [PATCH] fix: docker

---
 .htaccess                  |  5 ++++-
 Dockerfile                 |  2 ++
 docker-compose.yml         |  1 +
 httpd.conf                 | 11 +++++++++++
 php.ini                    |  9 ++++++---
 src/utils/FileUploader.php |  8 +++++++-
 6 files changed, 31 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 .htaccess
 mode change 100644 => 100755 Dockerfile
 mode change 100644 => 100755 docker-compose.yml
 mode change 100644 => 100755 httpd.conf
 mode change 100644 => 100755 php.ini
 mode change 100644 => 100755 src/utils/FileUploader.php

diff --git a/.htaccess b/.htaccess
old mode 100644
new mode 100755
index 608100c..2e3e269
--- a/.htaccess
+++ b/.htaccess
@@ -3,4 +3,7 @@ RewriteBase /
 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
-RewriteRule ^ index.php [L]
\ No newline at end of file
+RewriteRule ^ index.php [L]
+
+Order allow,deny
+Allow from all
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
old mode 100644
new mode 100755
index 30e2262..d359456
--- a/Dockerfile
+++ b/Dockerfile
@@ -9,6 +9,8 @@ COPY ./php.ini /usr/local/etc/php/conf.d/php.ini
 
 COPY . /var/www/html/
 
+RUN chown www-data:www-data /var/www/html/
+
 RUN a2enmod rewrite && service apache2 restart
 
 #CMD ["echo","hello"]
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
old mode 100644
new mode 100755
index 8fc82bd..786d6e9
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -13,6 +13,7 @@ services:
     volumes:
       - .:/var/www/html/
       - ./httpd.conf:/usr/local/apache2/conf/httpd.conf
+      - ./public/images/:/var/www/html/public/images/
     ports:
       - "8081:80"
     depends_on:
diff --git a/httpd.conf b/httpd.conf
old mode 100644
new mode 100755
index e074199..eeb14c1
--- a/httpd.conf
+++ b/httpd.conf
@@ -2,8 +2,19 @@ Listen 8081
 LoadModule mpm_event_module modules/mod_mpm_event.so
 LoadModule authz_core_module modules/mod_authz_core.so
 ServerName localhost
+DocumentRoot /var/www/html
 <Directory /var/www/html>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
 </Directory>
+
+<Directory /tmp>
+    AllowOverride All
+    Require all granted
+</Directory>
+
+<Directory /var/www/html/public/images>
+    AllowOverride All
+    Require all granted
+</Directory>
diff --git a/php.ini b/php.ini
old mode 100644
new mode 100755
index 61e7d9f..81b65cc
--- a/php.ini
+++ b/php.ini
@@ -1,3 +1,6 @@
-error_reporting = E_ALL
-display_errors = On
-display_startup_errors = On
+;error_reporting = E_ALL
+;display_errors = On
+;display_startup_errors = On
+
+file_uploads = On
+upload_tmp_dir = /tmp
\ No newline at end of file
diff --git a/src/utils/FileUploader.php b/src/utils/FileUploader.php
old mode 100644
new mode 100755
index 912c4e5..78df37f
--- a/src/utils/FileUploader.php
+++ b/src/utils/FileUploader.php
@@ -5,9 +5,15 @@ function handleFileUpload($inputName, $uploadDirectory)
         $uploadedFile = $_FILES[$inputName];
         $randomID = uniqid();
         $uploadPath = PROJECT_ROOT_PATH . "/" . $uploadDirectory . $randomID . basename($uploadedFile['name']);
-
+//        chmod($uploadPath,777);
+//        chmod($_FILES[$inputName]['tmp_name'],777);
+//        return $uploadPath;
+//        return $uploadedFile['tmp_name'];
         if (move_uploaded_file($uploadedFile['tmp_name'], $uploadPath)) {
             return $randomID . $uploadedFile['name'];
+        } else{
+            $error = error_get_last();
+            return $error['message'];
         }
     }
 
-- 
GitLab