initial commit

This commit is contained in:
patric 2025-03-28 20:24:45 +01:00
commit 9c93cdaa8a
7 changed files with 90 additions and 0 deletions

1
.gitignore vendored Normal file
View File

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

26
README.md Normal file
View File

@ -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
config.php Normal file
View File

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

2
dagenioFileReceiver.bat Normal file
View File

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

45
dagenioFileReceiver.php Normal file
View File

@ -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 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 MiB