2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * Interface for the zip extension
11 * Gets zip file contents
14 * @return array ($error_message, $file_data); $error_message
15 * is empty if no error
19 function PMA_getZipContents($file)
23 $zip_handle = zip_open($file);
24 if (is_resource($zip_handle)) {
25 $first_zip_entry = zip_read($zip_handle);
26 if (false === $first_zip_entry) {
27 $error_message = $GLOBALS['strNoFilesFoundInZip'];
29 /* Is the the zip really an ODS file? */
30 $read = zip_entry_read($first_zip_entry);
31 $ods_mime = 'application/vnd.oasis.opendocument.spreadsheet';
32 if (!strcmp($ods_mime, $read)) {
33 /* Return the correct contents, not just the first entry */
35 $entry = zip_read($zip_handle);
36 if (is_resource($entry)) {
37 if (!strcmp('content.xml', zip_entry_name($entry))) {
38 zip_entry_open($zip_handle, $entry, 'r');
39 $file_data = zip_entry_read($entry, zip_entry_filesize($entry));
40 zip_entry_close($entry);
45 * Either we have reached the end of the zip and still
46 * haven't found 'content.xml' or there was a parsing
47 * error that we must display
49 if ($entry === FALSE) {
50 $error_message = $GLOBALS['strErrorInZipFile'] . ' Could not find "content.xml"';
52 $error_message = $GLOBALS['strErrorInZipFile'] . ' ' . PMA_getZipError($zip_handle);
59 zip_entry_open($zip_handle, $first_zip_entry, 'r');
60 /* File pointer has already been moved, so include what was read above */
62 $file_data .= zip_entry_read($first_zip_entry, zip_entry_filesize($first_zip_entry));
63 zip_entry_close($first_zip_entry);
67 $error_message = $GLOBALS['strErrorInZipFile'] . ' ' . PMA_getZipError($zip_handle);
69 zip_close($zip_handle);
70 return (array('error' => $error_message, 'data' => $file_data));
74 * Gets zip error message
76 * @param integer error code
77 * @return string error message
80 function PMA_getZipError($code)
82 // I don't think this needs translation
84 case ZIPARCHIVE
::ER_MULTIDISK
:
85 $message = 'Multi-disk zip archives not supported';
87 case ZIPARCHIVE
::ER_READ
:
88 $message = 'Read error';
90 case ZIPARCHIVE
::ER_CRC
:
91 $message = 'CRC error';
93 case ZIPARCHIVE
::ER_NOZIP
:
94 $message = 'Not a zip archive';
96 case ZIPARCHIVE
::ER_INCONS
:
97 $message = 'Zip archive inconsistent';