PHP Classes

Storing Paths in ZIP

Recommend this page to a friend!

      Zip and File Splitter  >  All threads  >  Storing Paths in ZIP  >  (Un) Subscribe thread alerts  
Subject:Storing Paths in ZIP
Summary:Trying to find out how to stop storing paths in the zip file
Messages:2
Author:Henry Wills
Date:2008-04-10 11:18:37
Update:2012-06-13 12:29:00
 

  1. Storing Paths in ZIP   Reply   Report abuse  
Picture of Henry Wills Henry Wills - 2008-04-10 11:18:38
Hi, does anyone happen to know how to NOT store the path in the zip file? I am pulling files from a UNIX file path because they are not in the webpath, so my zip ends up with /var, /www .. etc as folders and all I need are the files with no paths.

Thanks
Henry

  2. Re: Storing Paths in ZIP   Reply   Report abuse  
Picture of Bas de Ruiter Bas de Ruiter - 2012-06-13 12:29:00 - In reply to message 1 from Henry Wills
I too found this anoying.
After searching for a solution to this, I eventually cam up with the simple solution to just first go to the directory before zipping the file.

<?php
// the input file
$file = '/path/to/file.txt';
$path = pathinfo($file, PATHINFO_DIRNAME);
$filename = basename($file);
// first change directory
chdir($path);
// then create zip file
require_once 'EasyZip.php';
$zip = new EasyZip();
$zip->addFile($filename);
$zip->zipFile('/path/to/zipfile.zip');
?>

 
For more information send a message to info at phpclasses dot org.