1. Go to this page and download the library: Download guinso/hx-http library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guinso / hx-http example snippets
$httpHeader = new \Hx\Http\HeaderReader();
$httpInputService = new \Hx\Http\InputService();
$arrInfo = $httpInputService.getInput($httpHeader);
//to read general input (no matter GET, POST, or PUT)
$yourClientDataValue = $arrInfo['data']['your-client-specified-data-key'];
//to read client uploaded file path (work for multipart format as well)
$clientUploadTemporaryFilePath = $arrInfo['file']['your-client-specified-file-name'];
$outputService = new \Hx\Http\OutputService();
$outputData = array(
'key-A' => 123,
'key-B' => 'Cat meow',
'key-C' => [
'sub-key-1' => 157.67,
'sub-key-2' => "tree"
]
);
//generate JSON output to http
$outputService->generateOutput('json', $outputData);
//OR generate in XML format
$outputService->generateOutput('xml', $outputData);
$outputService = new \Hx\Http\OutputService();
$htmlOutput = array(
'header' => //this is html header tag
"<title>Page Title</title>
<link rel="stylesheet" href="mystyle.css">",
'body' => //this is html body tag
"<body>
...
</body>"
);
//generate Html output format
$outputService->generateOutput('html', $htmlOutput);
$outputService = new \Hx\Http\OutputService();
$fileInfo = array(
'fileName' => 'filename-which-you-want-show-to-client',
'filePath' => 'actual-physical-file-path'
);
//download file to client (client never know physical file location)
$outputService->generateOutput('file', $fileInfo);
$outputService = new \Hx\Http\OutputService();
$data = array("data" => "anything....");
//generate plain text to client
//NOTE: output is not in Html format since it is marked as 'text/plain' MIME type
$outputService->generateOutput('text', $data);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.