protected function zip_upload($fobject, $name, $data, $action, $item) { $res = array(); $mtype = MIME::type_for_file($fobject->original_name); if ($mtype->type == 'application/zip;zip') { $zip = new ZipArchive(); $ro = $zip->open($fobject->path); if ($ro === true) { $dir = CMS::temp_dir() . '/' . $fobject->name; $dir_object = IO_FS::mkdir($dir, null, true); if ($dir_object) { $zip->extractTo($dir); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)); foreach ($objects as $k => $object) { $base = trim($object->getBasename($object->getExtension()), '. '); if ('' !== $base) { $upload = Net_HTTP::Upload($object->getPathname(), $object->getFilename(), array('name' => $object->getFilename(), 'type' => MIME::type_for_file($object->getPathname())->type, 'tmp_name' => $object->getPathname(), 'error' => 0, 'size' => $object->getSize())); $res[] = $this->upload_file($upload, $name, $data, $action, $item); } } $dir_object->rm(); } $zip->close(); } } return $res; }
/** * @param array $nfiles */ protected function create_objects(array &$files) { foreach ($files as $name => &$file) { if (is_array($file)) { if (count($file) == 5 && is_string($file[0]) && is_string($file[1]) && is_string($file[2]) && is_int($file[3]) && is_int($file[4])) { if ($file[3] === UPLOAD_ERR_OK) { $file = Net_HTTP::Upload($file[2], $file[0], array('name' => $file[0], 'type' => $file[1], 'tmp_name' => $file[2], 'error' => $file[3], 'size' => $file[4])); } else { $file = null; } } else { $this->create_objects($file); } } } }