Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your images are in files, use PHP's <a href="http://php.net/manual/en/function.readfile.php" rel="nofollow">readfile()</a> function, and send a content-type header before outputting it:</p> <pre><code>&lt;?php $imagePaths = array( '1' =&gt; 'file1.png', '2' =&gt; 'file2.png', '3' =&gt; 'file3.png', ); $type = $_GET['img']; if ( isset($imagePaths[$type]) ) { $imagePath = $imagePaths[$type]; header('Content-Type: image/png'); readfile($imagePath); } else { header('HTTP/1.1 404 File Not Found'); echo 'File not found.'; } ?&gt; </code></pre> <p><strong>EDIT:</strong><br> You could also embed your images in the script by encoding them e.g. as <a href="http://en.wikipedia.org/wiki/Base64" rel="nofollow">Base64</a>, then embed them as strings in PHP, then decode it there with <a href="http://php.net/manual/en/function.base64-decode.php" rel="nofollow">base64_decode</a> to deliver them:</p> <pre><code>&lt;?php $imageData = array( '1' =&gt; '...', // Base64-encoded data as string ... ); $type = $_GET['img']; if ( isset($imageData[$type]) ) { header('Content-Type: image/png'); echo base64_decode($imageData[$type]); } else { header('HTTP/1.1 404 File Not Found'); echo 'File not found.'; } ?&gt; </code></pre> <p>You could also use PHP to encode the image on the command line. Just execute this PHP script in the command line (<code>php script.php image1.png image2.png image3.png &gt; output.php</code>) and save its output, and incorporate it into your script:</p> <pre><code>&lt;?php $imageData = array(); foreach ($argv as $index =&gt; $imagePath) $imageData[(string)($index + 1)] = base64_encode(file_get_contents($imagePath)); echo '$imageData = '.var_export($imageData, true).';'; ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload