It is currently Sat Feb 04, 2012 3:45 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Create Zip file issue
PostPosted: Thu Jan 28, 2010 6:17 pm 
Offline

Joined: Thu Jan 28, 2010 6:16 pm
Posts: 2
hi,
i have to convert folder to zip.

my script path is www.domainname.com/create_zip.php
Folder location : www.domainname.com/Main_dir/12343/sample/test.jpg.
i wants to zip the sample folder alone.

if i create means it will come along with the root directory (Main_dir/12343/sample)

i need only sample folder content to be zipped. no trace for parent directory.

how to proceed.
thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 08, 2010 6:14 pm 
Offline

Joined: Mon Feb 01, 2010 6:56 pm
Posts: 4
I made this using zip.lib.php(it goes with http://www.phpmyadmin.net) but I zipped from strings(just fread their contents and gaev them names directly).
But I'm not sure that this advice will help you. Please show your code.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 09, 2010 6:58 am 
Offline

Joined: Thu Jan 28, 2010 6:16 pm
Posts: 2
hi,
thanks for ur response.

i found another solution.
find below.

$dirName = $path;

if (!is_dir($dirName)) {
throw new Exception('Directory ' . $dirName . ' does not exist');
}

$dirName = realpath($dirName);
if (substr($dirName, -1) != '/') {
$dirName.= '/';
}
$dirStack = array($dirName);
$cutFrom = strrpos(substr($dirName, 0, -1), '/')+1;
while (!empty($dirStack)) {
echo $currentDir = array_pop($dirStack);
echo "<br>";
$filesToAdd = array();

$dir = dir($currentDir);
while (false !== ($node = $dir->read())) {
if (($node == '..') || ($node == '.')) {
continue;
}
if (is_dir($currentDir . $node)) {
array_push($dirStack, $currentDir . $node . '/');
}
if (is_file($currentDir . $node)) {
$filesToAdd[] = $node;
}
}

echo $localDir = substr($currentDir, $cutFrom);
echo "<br>";
$zip->addEmptyDir($localDir);

foreach ($filesToAdd as $file) {
$zip->addFile($currentDir . $file, $localDir . $file);
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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

Search for:
Jump to:  
cron