I'm working on a bundling system for my applications where a user can upload a compressed zip file with the following structure:
name_of_file.zip
src/
file.jar
thumbnail.png
meta.json
I would like to validate this structure after extraction with PHP. After the structure is validated, I will move thumbnail.png and /src/source.jar onto my server. I will also parse meta.json and return the data from it.
So here's what my class looks like so far ($this->archive is an instance of ZipArchive):
/**
* Process and parse a bundle.
*
* @param \UploadedFile $zip
* @param array $paths
*
* @return boolean
*/
private function bundle($zip, array $paths)
{
$status = $this->archive->open($zip->getRealPath());
if($status === false)
return false;
// Before getting here I need to verify the files exist...
$this->archive->extractTo($paths['software'], ['src/file.jar']);
$this->archive->extractTo($paths['thumbnail'], ['thumbnail.png']);
// Cool, files moved now read the meta.json file...
}
and if you already guessed it, it's laravel.
I'm only looking to validate structure right now. Once I'm done with the structure I'll need to do some simple file validation (some tips on getting the file extensions?).
At the end of all of this, file.jar and thumbnail.png will be moved to their locations and meta.json will be parsed and data from it returned (file not to be moved).