added an image file for transfer and chagnes to api
This commit is contained in:
parent
cfeacbb06d
commit
d5ecd60790
13
api.php
13
api.php
@ -9,8 +9,7 @@ $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) {
|
||||||
$filename = "test.txt";
|
$filename = "wifi.png";
|
||||||
$file_contents = file_get_contents($filename);
|
|
||||||
|
|
||||||
$attachment_location = $_SERVER["DOCUMENT_ROOT"] . $filename;
|
$attachment_location = $_SERVER["DOCUMENT_ROOT"] . $filename;
|
||||||
$headers = [];
|
$headers = [];
|
||||||
@ -18,15 +17,15 @@ $api->any('/', function ($requst) {
|
|||||||
if (file_exists($attachment_location)) {
|
if (file_exists($attachment_location)) {
|
||||||
$headers[] = $_SERVER["SERVER_PROTOCOL"] . " 200 OK";
|
$headers[] = $_SERVER["SERVER_PROTOCOL"] . " 200 OK";
|
||||||
$headers[] = "Cache-Control: public";
|
$headers[] = "Cache-Control: public";
|
||||||
$headers[] = "Content-Type: application/text";
|
$headers[] = "Content-Type: application/png";
|
||||||
$headers[] = "Content-Transfer-Encoding: Binary";
|
$headers[] = "Content-Transfer-Encoding: Binary";
|
||||||
$headers[] = "Content-Length:".filesize($attachment_location);
|
$headers[] = "Content-Length:".filesize($attachment_location);
|
||||||
$headers[] = "Content-Disposition: attachment; filename={$file_contents}";
|
$headers[] = "Content-Disposition: attachment; filename={$filename}";
|
||||||
// die();
|
die();
|
||||||
} else {
|
} else {
|
||||||
// die("Error: File not found.");
|
die("Error: File not found.");
|
||||||
}
|
}
|
||||||
return new Response(200, $headers, $file_contents);
|
return new Response(200, $headers, $filename);
|
||||||
});
|
});
|
||||||
|
|
||||||
$api->get('/hello/{name}', function ($requst, $name) {
|
$api->get('/hello/{name}', function ($requst, $name) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user