|
|
| |
1. zip arhive without a directory hierarchy |
|
Reply |
|
|
 Vladimir | 2009-11-29 04:52:37 |
How I can create zip arhive without a directory hierarchy?
example:
I have files in dir: /home/ftp/files/file.txt
I get arhive file.zip in arhive is: \home\ftp\files\file.txt
I need arhive file.zip in arhive: file.txt
P.S. sorry for my English.
|
| |
2. Re: zip arhive without a directory hierarchy |
|
Reply |
|
|
 Er. Rochak Chauhan | 2009-11-30 10:44:25 - In reply to message 1 from Vladimir |
Hi
Well to add directory/directories to a zip you use this method:
$createZipFile->addDirectory($outputDir);
You can use this method in a for loop, for multiple directories.
Example is:
<?php
$fileToZip="License.txt";
$fileToZip1="CreateZipFileMac.inc.php";
$fileToZip2="CreateZipFile.inc.php";
$directoryToZip="./"; // This will zip all the file(s) in this present working directory
$outputDir="/"; //Replace "/" with the name of the desired output directory.
$zipName="test.zip";
include_once("CreateZipFile.inc.php");
$createZipFile=new CreateZipFile;
/*
// Code to Zip a single file
$createZipFile->addDirectory($outputDir);
$fileContents=file_get_contents($fileToZip);
$createZipFile->addFile($fileContents, $outputDir.$fileToZip);
*/
//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip,$outputDir);
$rand=md5(microtime().rand(0,999999));
$zipName=$rand."_".$zipName;
$fd=fopen($zipName, "wb");
$out=fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);
@unlink($zipName);
?> |
| |
3. Re: zip arhive without a directory hierarchy |
|
Reply |
|
|
 Wojt Taj | 2010-01-26 17:53:02 - In reply to message 2 from Er. Rochak Chauhan |
Hello,
I have the same problem. I need to zip multiple files. Everything works fine but result zip files include trees of subdirectories. For example if I pass a file:
$fileToZip="/var/www/assets/Uploads/example.doc";
I get a zip file with directory structure /var/www/assets/Uploads/
How can I avoid that and have all my files placed in a single directory?
|
| |
4. Re: zip arhive without a directory hierarchy |
|
Reply |
|
|
 Er. Rochak Chauhan | 2010-01-27 01:21:34 - In reply to message 3 from Wojt Taj |
Simple...
Replace
$fileToZip="/var/www/assets/Uploads/example.doc";
With
$fileToZip="/SomeDir/example.doc";
:)
|
| |
5. Re: zip arhive without a directory hierarchy |
|
Reply |
|
|
 Wojt Taj | 2010-01-27 08:11:06 - In reply to message 4 from Er. Rochak Chauhan |
Hi,
Thanks for your reply. I'm afraid it's not that simple. I need to keep the files in such a folder hierarchy as the project is running on Silverstripe and the files are content managed. The actual path is even longer but I shortened it just to explain the problem.
|
| |
6. Re: zip arhive without a directory hierarchy |
|
Reply |
|
|
 Er. Rochak Chauhan | 2010-01-27 09:15:56 - In reply to message 5 from Wojt Taj |
Wojt Taj
I would recon you contact me via any IM, Will clear all your doubts in one session.
My ID in every popular IM is: rochakchauhan |
| |
7. Re: zip arhive without a directory hierarchy |
|
Reply |
|
|
 Marcus Hjortsberg | 2011-08-10 13:37:03 - In reply to message 6 from Er. Rochak Chauhan |
I have the same request.
Can some code please be posted here so that I can get rid of the folder hierarchy?
Thanx in advance! |
|