emptygif
भाषा: मराठी

सर्व भाषा आणि फ्रेमवर्क

Slim PHP

Slim साठी PHP स्निपेट, जो /pixel.gif वरच्या रिक्वेस्टना empty GIF ने उत्तर देतो. GIF स्टार्टअपला एकदाच डिकोड होतो.

Slim PHP

इन्स्टॉल
composer require slim/slim slim/psr7
फाइल
index.php
चालवा
php -S 0.0.0.0:8080 index.php
<?php

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

require __DIR__ . '/vendor/autoload.php';

$gif = base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

$app = AppFactory::create();

$app->get('/pixel.gif', function (Request $request, Response $response) use ($gif) {
    $response->getBody()->write($gif);

    return $response
        ->withHeader('Content-Type', 'image/gif')
        ->withHeader('Content-Length', (string) strlen($gif))
        ->withHeader('Cache-Control', 'no-store');
});

$app->run();

आम्ही हा स्निपेट चालवला आणि त्याने परत केलेले बाइट्स तुलना करून पाहिले.

तपासा

curl -sI http://localhost:8080/pixel.gif

अधिकृत साइट: Slim

PHP मध्ये आणखी