Guest User

Untitled

a guest
Jun 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Downloader for a file which is embedded in an URL
  5. *
  6. * Free to use!
  7. *
  8. * @author Fabian Rehhauße
  9. * @country Germany
  10. * @date 06-16-2018
  11. */
  12.  
  13. if(isset($_POST["submit"])) {
  14. $href = "#";
  15. $b64 = base64_encode(file_get_contents($_FILES["fileToUpload"]['tmp_name']));
  16. $name = base64_encode(basename($_FILES["fileToUpload"]['name']));
  17. $href = "?filename=$name&content=$b64";
  18.  
  19. unlink($_FILES["fileToUpload"]['tmp_name']);
  20.  
  21. echo("<!DOCTYPE html>\n");
  22. echo("<html>");
  23. echo("<body>");
  24. echo("<a href=\"$href?>\">Your file link</a>");
  25. echo("</body>");
  26. echo("</html>");
  27. }
  28. elseif(isset($_GET['content'])){
  29. $b64_content = str_replace(" ", "+", $_GET['content']);
  30. $filename = "File";
  31.  
  32. if(isset($_GET['filename'])){
  33. $filename = str_replace("\"", "_", base64_decode($_GET['filename']));
  34. $filename = str_replace("\\", "_", $filename);
  35. $filename = str_replace("/", "_", $filename);
  36. $filename = str_replace(" ", "_", $filename);
  37. }
  38.  
  39. header('Content-Description: File Transfer');
  40. header('Content-Type: application/octet-stream');
  41. header('Content-Disposition: attachment; filename="'.basename($filename).'"');
  42. header('Expires: 0');
  43. header('Cache-Control: must-revalidate');
  44. header('Content-Length: ' . strlen(base64_decode($b64_content)));
  45. header('Pragma: public');
  46.  
  47. echo(base64_decode($b64_content));
  48. }
  49. else {
  50. echo("<!DOCTYPE html>\n");
  51. echo('<html>');
  52. echo('<body>');
  53. echo('<form action="?" method="post" enctype="multipart/form-data">');
  54. echo('Select file to upload:');
  55. echo('<input type="file" name="fileToUpload" id="fileToUpload">');
  56. echo('<input type="submit" value="Upload" name="submit">');
  57. echo('</form>');
  58. echo('</body>');
  59. echo('</html>');
  60. }
Add Comment
Please, Sign In to add comment