Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One note worth adding is to make sure you're code does not generate "unauthorized" sizes of these images.</p> <p>So the following URL will create a 200x200 version of image 1234 if one doesn't already exist. I'd <strong>highly</strong> suggest you make sure that the requested URL contains image dimensions you support. </p> <pre><code>/images/get/200x200/1234.jpg </code></pre> <p>A malicious person could start requesting random URLs, always altering the height &amp; width of the image. This would cause your server some serious issues b/c it will be sitting there, essentially under attack, generating images of sizes you do not support.</p> <pre><code>/images/get/0x1/1234.jpg /images/get/0x2/1234.jpg ... /images/get/0x9999999/1234.jpg /images/get/1x1/1234.jpg ... etc </code></pre> <p>Here's a random snip of code illustrating this:</p> <pre><code>&lt;?php $pathOnDisk = getImageDiskPath($_SERVER['REQUEST_URI']); if(file_exists($pathOnDisk)) { // send header with image mime type echo file_get_contents($pathOnDisk); exit; } else { $matches = array(); $ok = preg_match( '/\/images\/get\/(\d+)x(\d+)\/(\w+)\.jpg/', $_SERVER['REQUEST_URI'], $matches); if(! $ok) { // invalid url handleInvalidRequest(); } else { list(, $width, $height, $guid) = $matches; // you should do this! if(isSupportedSize($width, $height)) { // size is supported. all good // generate the resized image, save it &amp; output it } else { // invalid size requested!!! handleInvalidRequest(); } } } // snip function handleInvalidRequest() { // do something w/ invalid request // show a default graphic, log it etc } ?&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