note 25551 added to function.zip-entry-name
| From: | leandro_dealmeida at hotmail dot com | Date: | Fri, 27 Sep 2002 14:21:20 +0000 |
| Subject: | note 25551 added to function.zip-entry-name | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37328@lists.php.net to get a copy of this message | ||
If you want to get the real name of the file without the directory name, you can just use the
function basename() as the follow:
<?
$zip_dir = "./import/";
$zip = zip_open($zip_dir."import.zip");
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$file = basename(zip_entry_name($zip_entry));
$fp = fopen($zip_dir.basename($file), "w+");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
zip_entry_close($zip_entry);
}
fwrite($fp, $buf);
fclose($fp);
echo "The file ".$file." was extracted to dir
".$zip_dir."\n<br>";
}
zip_close($zip);
}
?>
Thefore you can extract files without concern with the directory that is set inside the zip source.
Remember to give write permission (w) on that directory.
Hello from Brazil.
Leandro
--
http://www.php.net/manual/en/function.zip-entry-name.php
http://master.php.net/manage/user-notes.php?action=edit+25551
http://master.php.net/manage/user-notes.php?action=delete+25551
http://master.php.net/manage/user-notes.php?action=reject+25551