这是我尝试解决的:我想允许通过默认的filefield上载内容类型上传zip文件。我正在使用hook_node_preSave拍摄zip文件,并从基于核心更新管理器的帮助函数中提取。我收到的错误是:
注意:未定义的索引:filefield_unzip_node_presave()中的文件名()(第18行) /sites/all/modules/filefield_unzip/filefield_unzip.module)。 注意:未定义的索引:filefield_unzip_node_presave()中的URI(第19行) /sites/all/modules/filefield_unzip/filefield_unzip.module)。 例外:归档者只能在本地文件上运行:> archiver_get_archiver()不支持(/包含/包含的行8149 /common.inc)。
这是我的代码:
/** * @file * Allows uploading and extracting a zip file uploaded to a file field. */ /** * * Implementation of hook_node_presave($node) * */ function filefield_unzip_node_presave($node) { if($node->type == 'game') { if (!empty($node->field_game_files)) { $zipFile = $node->field_game_files['und'][0]['filename']; $zipDirectory = $node->field_game_files['und'][0]['uri']; _filefield_unzip_archive_extract($zipFile, $zipDirectory); } } } /** * * Copy of the function used by the update manager update_manager_archive_extract($file, $directory) * */ function _filefield_unzip_archive_extract($file, $directory) { $archiver = archiver_get_archiver($file); if (!$archiver) { throw new Exception(t('Cannot extract %file, not a valid archive.', array('%file' => $file))); } //Remove the directory if it exists, otherwise it might contain a mixture of old files mixed with new files (e.g. in cases where files //were removed from a later release). $files = $archiver->listContents(); //Unfortunately, we can only use the direct name to determine the project name. Some archivers list the first file as the directory (i.e., MODULE/) //and others list an actual file (i.e., MODULE/README.TXT). $project = strtok($files[0], '/\'); $extract_location = $directory . '/' .$project; if (file_exists($extract_location)) { file_unmanaged_delete_recursive($extract_location); } $archiver->extract($directory); return $archiver; }