How to embed images in a single HTML / PHP file?

后端 未结 3 598
清酒与你
清酒与你 2020-11-30 06:44

I am creating a lightweight, single-file database administration tool and I would like to bundle some small icons with it. What is the best way to embed images in a HTML/PHP

3条回答
  •  借酒劲吻你
    2020-11-30 07:25

    For one PHP server side script try a base64 encode of the graphic and use a simple controller-style logic:

     array('mimetype' => 'image/png',
                                         'data' => '...'));
    /* use request path, e.g. index.php/photo.png */
    $action = substr($_SERVER['PATH_INFO'], 1);
    switch($action) {
    case (preg_match('/\.png$/', $action)?$action:!$action):
      header("Content-Type: {$images[$action]['mimetype']}");
      /* use expires to limit re-requests on navigation */
      $expires = gmdate('D, d M Y H:i:s \G\M\T', filetime(__FILE__) + 365*24*60*60);
      header("Expires: {$expires}");
      $data = base64_decode($images[$action]['data']);
      header('Content-Length: ' . strlen($data));
      echo $data;
      break;
    ...
    }
    ?>
    

提交回复
热议问题