emptygif
언어: 한국어

모든 언어 및 프레임워크

Slim PHP

/pixel.gif 요청에 빈 GIF로 응답하는 Slim용 PHP 스니펫입니다. 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의 다른 예제