Mark/api.php
2021-08-07 14:29:08 +03:00

41 lines
1.1 KiB
PHP

<?php
use Mark\App;
use Workerman\Protocols\Http\Response;
require 'vendor/autoload.php';
$api = new App('http://0.0.0.0:3500');
$api->count = 4; // process count
$api->any('/', function ($requst) {
$filename = "/test.txt";
$file_contents = file_get_contents($filename);
$attachment_location = $_SERVER["DOCUMENT_ROOT"] . $filename;
$headers = [];
if (file_exists($attachment_location)) {
$headers[] = $_SERVER["SERVER_PROTOCOL"] . " 200 OK";
$headers[] = "Cache-Control: public";
$headers[] = "Content-Type: application/text";
$headers[] = "Content-Transfer-Encoding: Binary";
$headers[] = "Content-Length:".filesize($attachment_location);
$headers[] = "Content-Disposition: attachment; filename={$file_contents}";
// die();
} else {
// die("Error: File not found.");
}
return new Response(200, $headers, $file_contents);
});
$api->get('/hello/{name}', function ($requst, $name) {
return "Hello $name";
});
$api->post('/user/create', function ($requst) {
return json_encode(['code'=>0 ,'message' => 'ok']);
});
$api->start();