/** * @param $dest_path * @param $dest_name * @param $source_file * @param string $contentType * @param bool $extract * @param bool $clean * @param bool $check_exist * * @throws \Exception * @return array */ protected function handleFile($dest_path, $dest_name, $source_file, $contentType = '', $extract = false, $clean = false, $check_exist = false) { $ext = FileUtilities::getFileExtension($source_file); if (empty($contentType)) { $contentType = FileUtilities::determineContentType($ext, '', $source_file); } if ((FileUtilities::isZipContent($contentType) || 'zip' === $ext) && $extract) { // need to extract zip file and move contents to storage $zip = new \ZipArchive(); if (true === $zip->open($source_file)) { return $this->extractZipFile($this->container, $dest_path, $zip, $clean); } else { throw new InternalServerErrorException('Error opening temporary zip file.'); } } else { $name = empty($dest_name) ? basename($source_file) : $dest_name; $fullPathName = FileUtilities::fixFolderPath($dest_path) . $name; $this->driver->moveFile($this->container, $fullPathName, $source_file, $check_exist); return ['name' => $name, 'path' => $fullPathName, 'type' => 'file']; } }