changed headers
This commit is contained in:
parent
ee14f2f02a
commit
63ccec083e
21
api.php
21
api.php
@ -9,9 +9,24 @@ $api = new App('http://0.0.0.0:3500');
|
|||||||
$api->count = 4; // process count
|
$api->count = 4; // process count
|
||||||
|
|
||||||
$api->any('/', function ($requst) {
|
$api->any('/', function ($requst) {
|
||||||
// return 'Hello world';
|
$filename = "/test.txt";
|
||||||
$data = "{'test':'ok'}";
|
$file_contents = file_get_contents($filename);
|
||||||
return new Response(200, ["Content-Type" => "application/json"], json_encode($data));
|
|
||||||
|
$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={$filename}";
|
||||||
|
die();
|
||||||
|
} else {
|
||||||
|
die("Error: File not found.");
|
||||||
|
}
|
||||||
|
return new Response(200, $headers, readfile($attachment_location));
|
||||||
});
|
});
|
||||||
|
|
||||||
$api->get('/hello/{name}', function ($requst, $name) {
|
$api->get('/hello/{name}', function ($requst, $name) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user