2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * Interface for the zip extension
10 * Gets zip file contents
13 * @return array ($error_message, $file_data); $error_message
14 * is empty if no error
17 function PMA_getZipContents($file)
21 $zip_handle = zip_open($file);
22 if (is_resource($zip_handle)) {
23 $first_zip_entry = zip_read($zip_handle);
24 if (false === $first_zip_entry) {
25 $error_message = __('No files found inside ZIP archive!');
27 /* Is the the zip really an ODS file? */
28 $read = zip_entry_read($first_zip_entry);
29 $ods_mime = 'application/vnd.oasis.opendocument.spreadsheet';
30 if (!strcmp($ods_mime, $read)) {
31 /* Return the correct contents, not just the first entry */
33 $entry = zip_read($zip_handle);
34 if (is_resource($entry)) {
35 if (!strcmp('content.xml', zip_entry_name($entry))) {
36 zip_entry_open($zip_handle, $entry, 'r');
37 $file_data = zip_entry_read($entry, zip_entry_filesize($entry));
38 zip_entry_close($entry);
43 * Either we have reached the end of the zip and still
44 * haven't found 'content.xml' or there was a parsing
45 * error that we must display
47 if ($entry === false) {
48 $error_message = __('Error in ZIP archive:') . ' Could not find "content.xml"';
50 $error_message = __('Error in ZIP archive:') . ' ' . PMA_getZipError($zip_handle);
57 zip_entry_open($zip_handle, $first_zip_entry, 'r');
58 /* File pointer has already been moved, so include what was read above */
60 $file_data .= zip_entry_read($first_zip_entry, zip_entry_filesize($first_zip_entry));
61 zip_entry_close($first_zip_entry);
65 $error_message = __('Error in ZIP archive:') . ' ' . PMA_getZipError($zip_handle);
67 zip_close($zip_handle);
68 return (array('error' => $error_message, 'data' => $file_data));
72 * Gets zip error message
74 * @param integer error code
75 * @return string error message
77 function PMA_getZipError($code)
79 // I don't think this needs translation
81 case ZIPARCHIVE
::ER_MULTIDISK
:
82 $message = 'Multi-disk zip archives not supported';
84 case ZIPARCHIVE
::ER_READ
:
85 $message = 'Read error';
87 case ZIPARCHIVE
::ER_CRC
:
88 $message = 'CRC error';
90 case ZIPARCHIVE
::ER_NOZIP
:
91 $message = 'Not a zip archive';
93 case ZIPARCHIVE
::ER_INCONS
:
94 $message = 'Zip archive inconsistent';