Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <?php
  2. // TODO: Sprawdzanie czy dana grafika istnieje (URL)
  3. if(!isset($_GET['source']) || empty($_GET['source']))
  4. exit();
  5.  
  6. $file = $_GET['source'];
  7.  
  8. //$file_path = explode('?', $file)[0];
  9. $file_path = trim($file, '/');
  10. $file_path = explode('?',$file_path)[0];
  11.  
  12. $SAVE_PATH = 'save/%s';
  13. $FILE_PATH = sprintf($SAVE_PATH, $file_path);
  14.  
  15.  
  16. if(!file_exists($FILE_PATH)) {
  17. $ch = curl_init('https://cdn.playa-games.com/res/tinyisland/'.$file_path);
  18. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  20.  
  21. $data = curl_exec($ch);
  22. $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  23. $contentLeng = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
  24.  
  25. curl_close($ch);
  26.  
  27. header('x-readed: nie');
  28. header('Content-Length: '.$contentLeng);
  29. header('Content-Type: '.$contentType);
  30. print($data);
  31.  
  32. if (!is_dir($FILE_PATH)) {
  33. $folder = substr($FILE_PATH, 0, strrpos($FILE_PATH, '/'));
  34. createDirectories($folder);
  35. }
  36. file_put_contents($FILE_PATH, $data);
  37.  
  38. } else {
  39. header('x-readed: tak');
  40. header('Content-Length: '.filesize($FILE_PATH));
  41. header('Content-Type: '.mime_content_type ($FILE_PATH));
  42. readfile($FILE_PATH);
  43. }
  44.  
  45. function createDirectories($path){
  46. $folders = explode('/', $path);
  47. for($i=0,$c=count($folders); $i < $c; $i++){
  48. $folcopy = [];
  49. $folcopy = array_slice ($folders, 0, $i+1);
  50. if(!is_dir(join('/', $folcopy)))
  51. mkdir(join('/', $folcopy));
  52. }
  53. }
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement