Download

Enables you to download files from the server. Hint: Use Sys to zip folders before you download.

Command line interface

Syntax

  1. $ download filename [filename ...]

Arguments

  • filename – (file) One or more files to download.

Example

download.php

  1. <?
  2. require("../plugin.php");
  3. if (is_ajax()) {
  4. if ($_POST["action"] == 'download') {
  5. if (!is_file($_POST['file'])) die("1".$_POST['file']); // not file
  6. if (!is_readable($_POST['file'])) die("2".$_POST['file']); // denied
  7. die("0".$_POST['file']);
  8. } else if ($_POST['action'] = 'fetch') {
  9. header('Content-Type: application/octet-stream');
  10. header('Content-Disposition: attachment; filename="'.$_POST['file'].'"');
  11. readfile($_POST['file']);
  12. }
  13. exit;
  14. }
  15. ?>
  16. /**
  17. * Download file
  18. **/
  19. TinyShell.plugins.download = new Class({
  20. description: "Download files from the server",
  21. run : function(terminal, args) {
  22. this.t = terminal;
  23. this.req = args.length;
  24. this.rec = 0;
  25. // async download check
  26. if (args.length) for (var i = 0; i < args.length; i++) this.t.ajax_request(this.print, "<?php echo $_AJAX_URL?>", "action=download&file="+encodeURIComponent(args[i]), true);
  27. else {
  28. terminal.print("download: usage: download filename [filename ...]");
  29. terminal.resume();
  30. }
  31. },
  32. print: function(r) {
  33. switch (r.substring(0, 1)) {
  34. case "1":
  35. this.t.print("download: `"+r.substring(1)+"' is not a file");
  36. break;
  37. case "2":
  38. this.t.print("download: unable to read file `"+r.substring(1)+"'; permission denied");
  39. break;
  40. default:
  41. r = r.substring(1);
  42. this.t.print("<a href='"+this.t.create_url("<?php echo $_AJAX_URL?>", "action=fetch&file="+encodeURIComponent(r))+"' target='_blank'>Download file: "+r+"</a>", true);
  43. }
  44. if (++this.rec >= this.req) this.t.resume();
  45. }
  46. });

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>