Jump to content

PHP unzip files without directory. help plz


unix4k

Recommended Posts

Dear sirs,

 

I need to upload files to FTP and To waste less time, I zip the files, but the problem that since it is Automation it zips with directory - like this  C:/DIR.zip 

in zip file I have a DIR/files....    How to unzip all files to main directory on the server.  Right now if the main dir is  /main/html/  it unzips to /main/html/dir/files

But I need /main/html/files

 

Thank you.

I use this:

 

<?php

@set_time_limit(0);

@ini_set('max_execution_time',0);

@ini_set('set_time_limit',0);

error_reporting(E_ALL);

ignore_user_abort(true);

 

// block count

if (!isset($_REQUEST['c'])) die('wrong param');

$blocksnum = intval($_REQUEST['c']);

 

echo "unpak...\n"; @flush();

 

$filename = dirname(__FILE__)."/abcdd1";

if ($blocksnum > 1) { // joining blocks

$filename = dirname(__FILE__)."/result.zip";

$fh = fopen("result.zip", "wb");

for($i=1; $i<=$blocksnum; $i++) {

$fh2 = fopen("abcdd$i", "rb");

$abcdd = fread($fh2, filesize("abcdd$i"));

fclose($fh2);

fwrite($fh, $abcdd);

}

fclose($fh);

unset($abcdd);

}

 

$pclziplibfile = "pclzip.lib.php";

require_once($pclziplibfile);

$archive = new PclZip($filename);

 

// unzip

if ($archive->extract(PCLZIP_OPT_PATH, './', PCLZIP_OPT_REPLACE_NEWER) == 0) die("error");

 

// show the archive

$list = $archive->listContent();

echo "Распаковано ".sizeof($list)." файлов:\n";

for ($i=0; $i<sizeof($list); $i++) {

if(!$list[$i]['folder']) $bytes = " - ".$list[$i]['size']." byte\n";

else $bytes = "";

echo "".$list[$i]['filename']."$bytes\n";

}

 

// delete files

echo "delete files:\n";

_del(__FILE__);

_del($pclziplibfile);

_del($filename);

for($i=($blocksnum > 1) ? 1 : 2; $i<=$blocksnum; $i++) _del("abcdd".$i);

echo "Finished!\n";

 

function _del($file) {

if (!@unlink($file)) echo "can't delete $file\n";

else echo "$file deleted\n";

}

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.