11<?php
2- function getCURL (string $ id , string $ password ) {
3- # API Download URL
4- $ downloadURL = filter_input (INPUT_ENV , 'TMP_API_DOWNLOAD_URL ' , FILTER_VALIDATE_URL , ['options ' => ['default ' => 'https://api.tempfiles.download/download/?id=%1$s&p=%2$s ' ]]);
5- $ d_url = sprintf ($ downloadURL , $ id , $ password );
6-
7- $ curl = curl_init ();
8- curl_setopt_array ($ curl , [
9- CURLOPT_URL => $ d_url ,
10- CURLOPT_RETURNTRANSFER => TRUE ,
11- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2 ,
12- CURLOPT_CUSTOMREQUEST => 'GET ' ,
13- CURLOPT_HTTPHEADER => [
14- "cache-control: no-cache "
15- ]
16- ]);
17- return $ curl ;
2+
3+ function download ($ file_source , $ file_target ) {
4+ $ rh = fopen ($ file_source , 'rb ' );
5+ $ wh = fopen ($ file_target , 'w+b ' );
6+ if (!$ rh || !$ wh ) {
7+ return false ;
8+ }
9+
10+ while (!feof ($ rh )) {
11+ if (fwrite ($ wh , fread ($ rh , 4096 )) === FALSE ) {
12+ return false ;
13+ }
14+ echo '' ;
15+ flush ();
16+ }
17+
18+ fclose ($ rh );
19+ fclose ($ wh );
20+
21+ return true ;
1822}
1923
2024function return404 () {
@@ -28,16 +32,20 @@ function return404() {
2832$ id = filter_var ($ url [1 ]);
2933$ password = filter_input (INPUT_GET , "p " );
3034
31- $ curl = getCURL ($ id , $ password );
35+ # API Download URL
36+ $ downloadURL = filter_input (INPUT_ENV , 'TMP_API_DOWNLOAD_URL ' , FILTER_VALIDATE_URL , ['options ' => ['default ' => 'https://api.tempfiles.download/download/?id=%1$s&p=%2$s ' ]]);
37+ $ d_url = sprintf ($ downloadURL , $ id , $ password );
38+
39+ $ result = download ($ d_url , "/tmp/ $ id.tmp " );
40+ if (!$ result )
41+ return404 ();
3242
3343// Execute cURL command and get response data
34- $ response = json_decode (curl_exec ($ curl ));
44+ $ response = json_decode (curl_exec (file_get_contents ("/tmp/ $ id.tmp " )));
45+
46+ unlink ("/tmp/ $ id.tmp " );
47+
3548
36- $ error = curl_error ($ curl );
37- if ($ error !== "" ) {
38- error_log ($ error );
39- return404 ();
40- }
4149
4250if ($ response ->data ) {
4351
0 commit comments