Selaa lähdekoodia

initial commit

patric 7 kuukautta sitten
commit
9c93cdaa8a
7 muutettua tiedostoa jossa 90 lisäystä ja 0 poistoa
  1. 1 0
      .gitignore
  2. 26 0
      README.md
  3. 16 0
      config.php
  4. 2 0
      dagenioFileReceiver.bat
  5. 45 0
      dagenioFileReceiver.php
  6. BIN
      uploads/20250318_102659.jpg
  7. BIN
      uploads2/20250318_102659.jpg

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+php-8.4.5-nts-Win32-vs17-x64

+ 26 - 0
README.md

@@ -0,0 +1,26 @@
+dagenio File Receiver
+
+Starts PHP Server on Port 8000 and listens for Files:
+
+Install:
+    - Download Windows PHP Binaries and place it in dagenioFileReceiver Folder
+    - replace "php-8.4.5-nts-Win32-vs17-x64" with your version in dagenioFileReceiver.bat
+
+getting started:
+    - change Auth Token in Config
+    - Setup possible Directories for storing files
+
+URL:
+    - http://<ip>:8000/
+
+HTTP Request:
+    Method
+        - POST
+    Authorization
+        - Bearer
+    Body: 
+        - form-data
+    Params:
+        - folder -> use short key from Config e.g. "uploads"
+        - file
+

+ 16 - 0
config.php

@@ -0,0 +1,16 @@
+<?php
+$arrConfig = [
+    'auth' => [
+        'bearer' => 'Mfz8PMmjqQPwZEhr2v1z',
+    ],
+    'directories' => [
+            'uploads' => [
+                'path' => 'C:\\dagenioFileReceiver\\uploads\\',
+            ],
+            
+            'uploads2' => [
+                'path' => 'C:\\dagenioFileReceiver\\uploads2\\',
+            ],
+        ],
+];
+?>

+ 2 - 0
dagenioFileReceiver.bat

@@ -0,0 +1,2 @@
+php-8.4.5-nts-Win32-vs17-x64\php.exe -S 0.0.0.0:8000 dagenioFileReceiver.php
+pause

+ 45 - 0
dagenioFileReceiver.php

@@ -0,0 +1,45 @@
+<?php
+require_once('config.php');
+
+//Bearer Auth
+if(@$_SERVER['HTTP_AUTHORIZATION'] != 'Bearer '.$arrConfig['auth']['bearer']){
+    response(403, 'invalid Bearer Token');
+}
+
+if(!empty($_POST['folder'])){
+    foreach($arrConfig['directories'] as $key=>$config){
+        if($_POST['folder']==$key){
+            $uploaddir = $config['path'];
+            $uploadfile = $uploaddir . basename( $_FILES['file']['name']);
+            break;
+        }
+    }
+
+    if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)){
+        response(200, "The file has been uploaded successfully");
+    }
+
+    else{
+        response(500, "There was an error uploading the file");
+    }
+
+} else {
+    response(422, 'parameter folder is missing');
+}
+
+function response($code, $message){
+    echo json_encode(['message'=>$message]);
+    header("HTTP/1.1 ".$code.' '.getCodeStatus($code));
+    die();
+}
+
+function getCodeStatus($code){
+    $arrCode = [
+        200 => 'OK',
+        403 => 'Forbidden',
+        422 => 'Unprocessable Entity',
+        500 => 'Server Error',
+    ];
+    return $arrCode[$code];
+}
+?>

BIN
uploads/20250318_102659.jpg


BIN
uploads2/20250318_102659.jpg