PHPWales 2020 - June 3rd to June 4th


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

ZipArchive::getFromNameReturns the entry contents using its name


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

Returns the entry contents using its name.



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 find the entry. The following values may be ORed.

  • ZipArchive::FL_UNCHANGED

  • ZipArchive::FL_COMPRESSED

  • ZipArchive::FL_NOCASE

Return Values

Returns the contents of the entry on success or FALSE on failure.


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);

See Also

add a note add a note

User Contributed Notes 1 note

henrik dot haftmann at gmail dot com
3 years 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