subdirectories
hello i have an issue whereby i use code to create a folder with directories in it and each of this directories have files in them i can confirm the file structure after php creates the folder, however after i make a zip file and on inspecting the zip file i realise it is just one parrent folder with files in it the sub folders are ignored during zip creation
I have noticed this as well.
What do you do to add the files? can you show some code?
//basiclally the $files is an array that can contain arrays like this one
`$files[$key][] = 'somedir/'.$somekey.'/somedir2/'.$omekey2.'/'.$somefile
private function s3Download($files,$coupon)
{
//declare a base directory for zip files
$dir_path = public_path().DIRECTORY_SEPARATOR.'downs'.DIRECTORY_SEPARATOR.$coupon.DIRECTORY_SEPARATOR;
//iterate through the $files multidimensional array creating a folder structure based on the "top level" key as top level folder name
foreach ($files as $name=>$thefile) {
if (is_array($thefile)) {
foreach ($thefile as $k=>$file) {
$base_dir = $name;
$folder = $dir_path.$base_dir;
if (!is_dir($folder)) {
File::makeDirectory($folder, $mode = 0775, $recursive = true);
}
//download the file from s3 and save it in dir structure created
$save_path = $folder.DIRECTORY_SEPARATOR.$original_name;
if (!file_exists($save_path)) {
$s3 = AWS::createClient('s3');
try{
$result = $s3->getObject(array(
'Bucket' => mybucket,
'Key' => $key,
'SaveAs' => $save_path,
));
} catch (S3Exception $e) {
return $e->getMessage() . "\n";
}
}
}
}
}
$download = $this->makeZip($dir_path,$coupon);
}
private function makeZip($filespath,$coupon)
{
$files = glob($filespath.'*');
// zip it
$zip = 'downs'.DIRECTORY_SEPARATOR.$coupon.'.zip';
$path = public_path().DIRECTORY_SEPARATOR.$zip;
Zipper::make($path)->add($files);
while (!$this->checkFile($path)) {
if ($this->checkFile($path)) {
break;
}
Zipper::make($path)->add($files);
}
$this->remove_dir($filespath);
$headers = array(
'Content-Type: application/octet-stream',
);
return Response::download($path,$coupon.'.zip',$headers);
}
if you have any trouble reading the above code i would be glad to clarify
This code looks fine, I need to write a test and investigate further.
Hi @Chumper though i have not tested the solution i think tis issue is caused by the '/*' in the glob function
Nope seems that was not the issue