11<?php
2-
32const ALLOW_RAW_OUTPUT = false ;
43// 是否开启 ?raw 选项,可能会消耗服务器较多流量
54
65function has_query ($ query )
76{
87 return isset ($ _GET [$ query ]);
98}
10- if (file_exists ('../url.csv ' )) {
9+
10+ if (file_exists (__DIR__ . '/url.csv ' )) // in the same folder
11+ $ imgs_array = file (__DIR__ . '/url.csv ' , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
12+ else if (file_exists ('../url.csv ' )) // in the parent folder
1113 $ imgs_array = file ('../url.csv ' , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
12- } else {
14+ else // for vercel runtime
1315 $ imgs_array = file ('http:// ' . $ _SERVER ['HTTP_HOST ' ] . '/url.csv ' , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
14- }
15- if (count ($ imgs_array ) == 0 ) {
16- $ imgs_array = ['https://http.cat/503 ' ];
17- }
16+ if (count ($ imgs_array ) == 0 ) $ imgs_array = array ('https://http.cat/503 ' );
17+
1818
19- $ id = $ _GET ['id ' ] ?? "" ;
19+ $ id = $ _GET ['id ' ] ? $ _GET [ ' id ' ] : "" ;
2020if (strlen ($ id ) > 0 && is_numeric ($ id )) {
2121 settype ($ id , 'int ' );
2222 $ len = count ($ imgs_array );
@@ -34,7 +34,7 @@ function has_query($query)
3434if (has_query ('json ' )) {
3535 header ('Access-Control-Allow-Origin: * ' );
3636 header ('Content-Type: application/json ' );
37- echo json_encode ([ 'id ' => $ id , 'url ' => $ imgs_array [$ id ]] );
37+ echo json_encode (array ( 'id ' => $ id , 'url ' => $ imgs_array [$ id ]) );
3838} else if (has_query ('raw ' )) {
3939 if (!ALLOW_RAW_OUTPUT ) {
4040 header ('HTTP/1.1 403 Forbidden ' );
@@ -43,6 +43,7 @@ function has_query($query)
4343 header ('Content-Type: image/png ' );
4444 echo file_get_contents ($ imgs_array [$ id ]);
4545} else {
46+ header ('Referrer-Policy: no-referrer ' );
4647 header ('Location: ' . $ imgs_array [$ id ]);
4748}
4849
0 commit comments