download.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. define("CHUNK_SIZE", 1024*1024); // Size (in bytes) of tiles chunk
  3. // Read a file and display its content chunk by chunk
  4. function readfile_chunked($filename, $retbytes = TRUE) {
  5. $buffer = "";
  6. $cnt =0;
  7. // $handle = fopen($filename, "rb");
  8. $handle = fopen($filename, "rb");
  9. if ($handle === false) {
  10. return false;
  11. }
  12. while (!feof($handle)) {
  13. $buffer = fread($handle, CHUNK_SIZE);
  14. echo $buffer;
  15. ob_flush();
  16. flush();
  17. if ($retbytes) {
  18. $cnt += strlen($buffer);
  19. }
  20. }
  21. $status = fclose($handle);
  22. if ($retbytes && $status) {
  23. return $cnt; // return num. bytes delivered like readfile() does.
  24. }
  25. return $status;
  26. }
  27. // Here goes your code for checking that the user is logged in
  28. // ...
  29. // ...
  30. $data = json_decode(file_get_contents("data.json"),true)[$_GET["sharingid"]];
  31. if(isset($_GET["chkpassword"])){
  32. if($_GET["chkpassword"] == $data["password"]){
  33. echo true;
  34. }else{
  35. echo false;
  36. }
  37. }else{
  38. $logged_in = false;
  39. if($_GET["password"] == $data["password"]){
  40. $logged_in = true;
  41. }
  42. if ($logged_in) {
  43. $filename = $data["path"];
  44. //$mimetype = "mime/type";
  45. $mimetype = mime_content_type($filename);
  46. header("Content-length:".filesize($filename));
  47. header("Content-Type: ".$mimetype );
  48. readfile_chunked($filename);
  49. }
  50. else {
  51. echo "Tabatha says you haven\"t paid.";
  52. }
  53. }
  54. ?>