Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Zip File Functions : zip_entry_read

zip_entry_read

Read from an open directory entry (PHP 4 >= 4.0.7, PHP 5 >= 5.2.0, PECL zip:1.0-1.9.0)
string zip_entry_read ( resource zip_entry [, int length] )

Reads from an open directory entry.

Parameters

zip_entry

A directory entry returned by zip_read().

length

The number of bytes to return. If not specified, this function will attempt to read 1024 bytes.

Note:

This should be the uncompressed length you wish to read.

Return Values

Returns the data read, or FALSE if the end of the file is reached.

Code Examples / Notes » zip_entry_read

matt

When reading from a zip file if the initial call to zip_entry_read() returns false it would be advisable to run mkdir with the file name since it it very likely that the zero length file was a directory and attempts to save the files within the directory will fail if you dont create it first

radon8472

I`ve got a big Problem with the "zip_entry_read" function, and I don`t unterstand what I did wrong.
I tried to write a function, wicht reads all zip Entries of a file into an Array. It worked, I can read alle Methadata from this array.
But when i try to read the content, I always get nothing.
This is an example whre you can see whats the problem:
when I read 10 Bytes content IN the funktion, it works, but when I try the same with the returnvalue (or with the refference of the entries), it won`t work.
With the result of the function, I can also read all the methadata (filename, size ...) but only the Content, seems to be emty after the function.
<?php
 require("zip_funct.inc.php");
 function test(&$zip_entry = null)
 {
   $zip = zip_open("test.zip");
   while( $tmp[] = zip_read($zip) );
   array_pop($tmp);
   $zip_entry = $tmp;
   $n = 2;
   var_dump($zip_entry);
   $buf = zip_entry_read($zip_entry[$n], 10);
   echo "CONTENT:\n------------------\n".$buf."\n";
   echo "------------------\n";
   echo "Name:               " . zip_entry_name($zip_entry[$n]) . "\n";
   echo "Actual Filesize:    " . zip_entry_filesize($zip_entry[$n]) . "\n";
   echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry[$n]) . "\n";
   echo "Compression Method: " . zip_entry_compressionmethod($zip_entry[$n]) . "\n";
//    echo fread($result, 50);
   return $zip_entry;
}
// ##################################################
//  test($zip_entry);  // try to get the zip_entries via Refference
   $zip_entry = test();  // try to get zip_entries s return value
   $n = 2;
   var_dump($zip_entry);
   $buf = zip_entry_read($zip_entry[$n], 10);
   echo "CONTENT:\n------------------\n".$buf."\n";
   echo "------------------\n";
   echo "Name:               " . zip_entry_name($zip_entry[$n]) . "\n";
   echo "Actual Filesize:    " . zip_entry_filesize($zip_entry[$n]) . "\n";
   echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry[$n]) . "\n";
   echo "Compression Method: " . zip_entry_compressionmethod($zip_entry[$n]) . "\n";
?>
The screenoutput looks like this:
array(8) {
 [0]=>
 resource(61) of type (Zip Entry)
 [1]=>
 resource(62) of type (Zip Entry)
// and a lot other entries
}
CONTENT:
------------------
<html>
<h
------------------
Name:               tmp.html
Actual Filesize:    1136
Compressed Size:    360
Compression Method: deflated
array(8) {
 [0]=>
 resource(61) of type (Zip Entry)
 [1]=>
 resource(62) of type (Zip Entry)
// and a lot other entries
}
CONTENT:
------------------
------------------
Name:               tmp.html
Actual Filesize:    1136
Compressed Size:    360
Compression Method: deflated
And this output shows, that the returnvalue of the function still as a valid ressource and still returns the correct methadata, but the content is empty.
I try to solve this problem since weeks and I realy need help. If anybody has an idea whats the Problem, please notice hear.


Change Language


Follow Navioo On Twitter
zip_close
zip_entry_close
zip_entry_compressedsize
zip_entry_compressionmethod
zip_entry_filesize
zip_entry_name
zip_entry_open
zip_entry_read
zip_open
zip_read
ZipArchive::addEmptyDir
ZipArchive::addFile
ZipArchive::addFromString
ZipArchive::close
ZipArchive::deleteIndex
ZipArchive::deleteName
ZipArchive::extractTo
ZipArchive::getArchiveComment
ZipArchive::getCommentIndex
ZipArchive::getCommentName
ZipArchive::getFromIndex
ZipArchive::getFromName
ZipArchive::getNameIndex
ZipArchive::getStream
ZipArchive::locateName
ZipArchive::open
ZipArchive::renameIndex
ZipArchive::renameName
ZipArchive::setArchiveComment
ZipArchive::setCommentIndex
ZipArchive::setCommentName
ZipArchive::statIndex
ZipArchive::statName
ZipArchive::unchangeAll
ZipArchive::unchangeArchive
ZipArchive::unchangeIndex
ZipArchive::unchangeName
eXTReMe Tracker