PHP 7.1.18 Released


(PHP 5 >= 5.2.0, PECL zip >= 1.1.0)

ZipArchive::getFromNameReturns the entry contents using its name


string ZipArchive::getFromName ( string $name [, int $length = 0 [, int $flags ]] )

Returns the entry contents using its name.

Elenco dei parametri


Name of the entry


The length to be read from the entry. If 0, then the entire entry is read.


The flags to use to open the archive. the following values may be ORed to it.

  • ZipArchive::FL_UNCHANGED

  • ZipArchive::FL_COMPRESSED

Valori restituiti

Returns the contents of the entry on success o FALSE in caso di fallimento.


Example #1 Get the file contents

= new ZipArchive;
if (
$zip->open('') === TRUE) {
} else {

Example #2 Convert an image from a zip entry

= new ZipArchive();
if (
$z->open(dirname(__FILE__) . '/')) {
$im_string $z->getFromName("pear_item.gif");
$im imagecreatefromstring($im_string);

Vedere anche:

add a note add a note

User Contributed Notes 1 note

henrik dot haftmann at gmail dot com
1 year ago
The handling of file names containing non-ASCII characters is undocumented. It seems that this function calls <?php mb_convert_encoding($name,"CP850","UTF-8") ?> and therefore expects DOS encoding in the zipfile but UTF-8 encoding for the name. If the zipfile uses UTF-8 names (Pkzip 4.5 / Winzip 11.2), this function fails. Use getFromIndex instead as a workaround.
To Top