View previous topic :: View next topic
Author
Message
sss.ark Joined: 28 Jan 2010 Posts: 2
Posted: Thu Jan 28, 2010 5:17 pm Post subject: Create Zip file issue
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.
Back to top
qforever Joined: 01 Feb 2010 Posts: 4
Posted: Mon Feb 08, 2010 5:14 pm Post subject:
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.
Back to top
sss.ark Joined: 28 Jan 2010 Posts: 2
Posted: Tue Feb 09, 2010 5:58 am Post subject:
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);
}
}
Back to top
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
PHP Forum :: MySQL Forum :: Java Script Forum