Login   Register  
PHP Classes
elePHPant
Icontem

zip arhive without a directory hierarchy

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Create ZIP File  >  All threads  >  zip arhive without a directory hierarchy  >  (Un) Subscribe thread alerts  
Subject:zip arhive without a directory hierarchy
Summary:zip arhive without a directory hierarchy?
Messages:8
Author:Vladimir
Date:2009-11-29 04:52:37
Update:2013-02-23 13:16:18
 

  1. zip arhive without a directory hierarchy   Reply   Report abuse  
Picture of Vladimir
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   Report abuse  
Picture of Er. Rochak Chauhan
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   Report abuse  
Picture of Wojt Taj
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   Report abuse  
Picture of Er. Rochak Chauhan
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   Report abuse  
Picture of Wojt Taj
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   Report abuse  
Picture of Er. Rochak Chauhan
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   Report abuse  
Picture of Marcus Hjortsberg
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!

  8. Re: zip arhive without a directory hierarchy   Reply   Report abuse  
Picture of bharti
bharti
2013-02-23 13:16:18 - In reply to message 7 from Marcus Hjortsberg
I have a folder : upload/
And in Database MySQL table column_name (resume_name, date, id).
I want to download some multiple files as zip file through MySQL query like 'x' date to 'x' date.
How can i do? Plz help me!

my form like:
---------------

Date From:------- Date To:---------- [Download Now]