PHP code example of neat / http

1. Go to this page and download the library: Download neat/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/ */

    

neat / http example snippets


 /** @var Neat\Http\ServerRequest $request */

// Get ?page= query parameter
$page = $request->query('page');

// Get posted name field
$name = $request->post('name');

// Or just get all posted fields
$post = $request->post();

// Who doesn't want a cookie
$preference = $request->cookie('preference');

// Get the request method
$method = $request->method();

// And of course the requested URL
$url = $request->url();

 /** @var Neat\Http\Url $url */

// You can easily print the URL because it converts to a string when needed
echo $url;

// Or get parts of the url separately
$url->scheme();   // 'https'
$url->username(); // ''
$url->password(); // ''
$url->host();     // 'example.com'
$url->port();     // null
$url->path();     // '/articles'
$url->query();    // 'page=2'
$url->fragment(); // ''

// Do you want to create a slightly different URL based on this one?
$mutation = $url->withPath('/just')->withQuery('tweak=any&part=youlike');

 /** @var Neat\Http\ServerRequest $request */

// Get uploaded file with the name avatar
$file = $request->files('avatar');

// Check the error status
if (!$file->ok()) {
    echo 'Upload error id = ' . $file->error();
}

// Get the file name, size and mime type
$file->clientName(); // 'selfie.jpg' <-- provided by the client, so consider it unsafe user input
$file->clientType(); // 'image/jpeg' <-- provided by the client, so consider it unsafe user input
$file->size(); // 21359

// Move the file from its temporary location
$file->moveTo('destination/path/including/filename.jpg');
file