AutoIndex PHP Script Forum Index AutoIndex PHP Script
A Website Directory Indexer
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Tar, Gzip and Zip functionality

 
Post new topic   Reply to topic    AutoIndex PHP Script Forum Index -> Development
View previous topic :: View next topic  
Author Message
Gingah
New Member
New Member


Joined: 02 Jun 2009
Posts: 2

PostPosted: Tue Jun 02, 2009 3:58 pm    Post subject: Tar, Gzip and Zip functionality Reply with quote

Hello,

First, I would like to express my admiration for AutoIndex; it makes PHP-based file browsing very easy, and is very useful in my webdevelopment. Secondly, I had problems getting the default Tar-compression working, and I really prefer Zip-archives, so I added functionality for them. I did this using the TAR/GZIP/BZIP2/ZIP Archives-class from phpclasses.org, and changing three files in my AutoIndex installation. I am dependant upon having the option to download entire directories with AutoIndex, and so I had to fix the Tar-bug I was experiencing somehow, and this was the result. To use this you MUST have PHP 5.2.0 or later installed, as zlib and bz2 was introduced there.

If anyone else would like to do the same, here are the installation instructions:

  1. Install AutoIndex 2.x (must be the PHP5 version, meaning PHP 5.2.x or later)
  2. Open index.php
  3. Find line 527, which contains $mime = new MimeType('.tar'); (It's line 527 in AutoIndex 2.2.4)
  4. Find line 533, which contains $tar = new Tar($list, $outfile, strlen($dir)); (It's line 533 in AutoIndex 2.2.4)
  5. Remove all code between line 527 and 533, meaning remove this:
    Code:
    $mime = new MimeType('.tar');
    header('Content-Type: ' . $mime -> __toString());
    header('Content-Disposition: attachment; filename="'
    . $outfile . '.tar"');
    @set_time_limit(0);
    $list = new DirectoryList($dir);
    $tar = new Tar($list, $outfile, strlen($dir));

  6. Where the code was, place the following code:
    Code:
    // TAR/GZIP/BZIP2/ZIP
    include('classes/archive.php');
    $compress = $_GET['compress'];
    if ($compress == 'tar') {
      $compress_output = new tar_file("$dir");
    } elseif ($compress == 'gzip') {
      $compress_output = new gzip_file("$dir");
    } elseif ($compress == 'bzip2') {
      $compress_output = new bzip_file("$dir");
    } elseif ($compress == 'zip') {
      $compress_output = new zip_file("$dir");
    }
    $compress_output->set_options(array('inmemory' => 1, 'overwrite' => 1, 'recurse' => 1, 'storepaths' => 1));
    $compress_output->add_files("$dir");
    $compress_output->create_archive();
    $compress_output->download_file();

  7. Save and close index.php

  8. Open templates/default/table_footer.tpl
  9. Find line 43, which contains <a class="autoindex_a" href="{info:archive_link}">{words:download directory as tar.gz archive}</a> (It's line 43 in AutoIndex 2.2.4)
  10. Remove the line
  11. Where the code was, place the following code:
    Code:
    <b>Download directory as</b>
      <a class="autoindex_a" href="{info:archive_link_tar}">Tar</a>,&nbsp;
      <a class="autoindex_a" href="{info:archive_link_gzip}">Gzip</a>,&nbsp;
      <a class="autoindex_a" href="{info:archive_link_zip}">Zip</a>&nbsp;

  12. Save and close table_footer.tpl

  13. Open classes/TemplateInfo.php
  14. Find line 83, which contains case 'archive_link': (It's line 83 in AutoIndex 2.2.4)
  15. Find line 88, which contains } (It's line 88 in AutoIndex 2.2.4)
  16. Remove all code between line 83 and 88, meaning remove this:
    Code:
    case 'archive_link':
    {
    global $config;
    return Url::html_output($_SERVER['PHP_SELF']) . '?archive=true&amp;dir='
    . substr($this -> dir_list -> __get('dir_name'), strlen($config -> __get('base_dir')));
    }

  17. Where the code was, place the following code:
    Code:
    case 'archive_link_tar':
    // Compress as Tar
    {
    global $config;
    $url = Url::html_output($_SERVER['PHP_SELF']) . '?archive=true&compress=tar&amp;dir='
    . substr($this -> dir_list -> __get('dir_name'), strlen($config -> __get('base_dir')));
    return $url;
    }
    case 'archive_link_gzip':
    // Compress as Gzip
    {
    global $config;
    $url = Url::html_output($_SERVER['PHP_SELF']) . '?archive=true&compress=gzip&amp;dir='
    . substr($this -> dir_list -> __get('dir_name'), strlen($config -> __get('base_dir')));
    return $url;
    }
    case 'archive_link_bzip2':
    // Compress as Bzip2
    {
    global $config;
    $url = Url::html_output($_SERVER['PHP_SELF']) . '?archive=true&compress=bzip2&amp;dir='
    . substr($this -> dir_list -> __get('dir_name'), strlen($config -> __get('base_dir')));
    return $url;
    }
    case 'archive_link_zip':
    // Compress as Zip
    {
    global $config;
    $url = Url::html_output($_SERVER['PHP_SELF']) . '?archive=true&compress=zip&amp;dir='
    . substr($this -> dir_list -> __get('dir_name'), strlen($config -> __get('base_dir')));
    return $url;
    }

  18. Save and close TemplateInfo.php

  19. Download the TAR/GZIP/BZIP2/ZIP Archives-class
  20. Or, if you do not wish to register at phpclasses.org, download the TAR/GZIP/BZIP2/ZIP Archives-class from this site
  21. Open the archive you downloaded
  22. Copy the file named archive.php
  23. Paste the file into the classes folder in your AutoIndex installation


Information: The class has an open license, provided you do not remove the developers copyright-comment at the top.

The links for downloading a directory as Tar, Gzip or Zip appears where the original link was; directly below the file/folder tables.
_________________
Back to top
View user's profile Send private message
mvveelen
New Member
New Member


Joined: 26 Aug 2009
Posts: 3

PostPosted: Wed Aug 26, 2009 12:53 pm    Post subject: Reply with quote

Wow !! Looks nice, but it doesn't work (for me).

I have PHP 5.2.10 and did everything you told to do (twice....) but : doesn't work.

If I try it, it only gets me a filename like : "index" with no extension, and for all 3 options. It does pack all files, but the filename is just : index

What could be wrong ?
Back to top
View user's profile Send private message
zlatan24
New Member
New Member


Joined: 13 Sep 2009
Posts: 3

PostPosted: Mon Dec 07, 2009 7:49 am    Post subject: Reply with quote

Today I downloaded a film in zip file and wanted to watch it,but I couldn't because it was damaged.A friend advised me next tool-corrupted program recovery zip.To my surprise utility helped me very easy and free of cost.Besides software showed how it can encounter problems with this application and corrupted files with *.zip extension.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoIndex PHP Script Forum Index -> Development All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

If you find AutoIndex useful, please support the script by donating.