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
18 function PMA_getZipContents($file)
22 $zip_handle = zip_open($file);
23 if (is_resource($zip_handle)) {
24 $first_zip_entry = zip_read($zip_handle);
25 if (false === $first_zip_entry) {
26 $error_message = __('No files found inside ZIP archive!');
28 /* Is the the zip really an ODS file? */
29 $read = zip_entry_read($first_zip_entry);
30 $ods_mime = 'application/vnd.oasis.opendocument.spreadsheet';
31 if (!strcmp($ods_mime, $read)) {
32 /* Return the correct contents, not just the first entry */
34 $entry = zip_read($zip_handle);
35 if (is_resource($entry)) {
36 if (!strcmp('content.xml', zip_entry_name($entry))) {
37 zip_entry_open($zip_handle, $entry, 'r');
38 $file_data = zip_entry_read($entry, zip_entry_filesize($entry));
39 zip_entry_close($entry);
44 * Either we have reached the end of the zip and still
45 * haven't found 'content.xml' or there was a parsing
46 * error that we must display
48 if ($entry === FALSE) {
49 $error_message = __('Error in ZIP archive:') . ' Could not find "content.xml"';
51 $error_message = __('Error in ZIP archive:') . ' ' . PMA_getZipError($zip_handle);
58 zip_entry_open($zip_handle, $first_zip_entry, 'r');
59 /* File pointer has already been moved, so include what was read above */
61 $file_data .= zip_entry_read($first_zip_entry, zip_entry_filesize($first_zip_entry));
62 zip_entry_close($first_zip_entry);
66 $error_message = __('Error in ZIP archive:') . ' ' . PMA_getZipError($zip_handle);
68 zip_close($zip_handle);
69 return (array('error' => $error_message, 'data' => $file_data));
73 * Gets zip error message
75 * @param integer error code
76 * @return string error message
78 function PMA_getZipError($code)
80 // I don't think this needs translation
82 case ZIPARCHIVE
::ER_MULTIDISK
:
83 $message = 'Multi-disk zip archives not supported';
85 case ZIPARCHIVE
::ER_READ
:
86 $message = 'Read error';
88 case ZIPARCHIVE
::ER_CRC
:
89 $message = 'CRC error';
91 case ZIPARCHIVE
::ER_NOZIP
:
92 $message = 'Not a zip archive';
94 case ZIPARCHIVE
::ER_INCONS
:
95 $message = 'Zip archive inconsistent';