thumb: prefix data path only for numeric roots
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Jun 2018 13:32:49 +0000 (15:32 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Jun 2018 19:58:28 +0000 (21:58 +0200)
Support other paths while retaining compatibility with /data-implied links.

thumb/index.php

index b49ca6ef47be6270f485de9509f1387a8fe6676a..5327192d0be49e85632679f256cacb5fa91b2306 100644 (file)
@@ -1,16 +1,16 @@
 <?php
 ob_clean();
 
-list ($height, $imgarg) = explode('/', ltrim($Args, '/'), 2);
+list ($height, $imgpath) = explode('/', ltrim($Args, '/'), 2);
 $width= 1000;
-$imgpath = "data/$imgarg";
+$imgpath = preg_replace('{^(?=[0-9]+/)}', 'data/', $imgpath, 1);
 
 if (!file_exists($imgpath)) {
        http_response_code(404);
        exit;
 }
 
-$target = preg_replace("{^data/}", "thumb/$height/", $imgpath, 1);
+$target = "thumb/$height/$imgpath";
 if (!file_exists($target)) {
        @mkdir(dirname($target), 0777, TRUE);