method export documentation in bbn\Ide\Actions

function($data) { $directories = new Directories($this->db); $dirs = $directories->dirs(); $root_dest = BBN_USER_PATH.'tmp/'.bbn\Str::genpwd().'/'; if ( isset($dirs[$data['dir']]) ){ if ( $this->isMvc($dirs[$data['dir']]) ){ foreach ( $dirs[$data['dir']]['files'] as $f ){ $dest = $root_dest.$data['name'].'/'.str_replace(\bbn\Mvc::getAppPath(), '', $f['fpath']); if ( $data['type'] === 'file' ){ $ext = bbn\Str::fileExt($data['path']); $path = substr($data['path'], 0, Strrpos($data['path'], $ext)); $file = $f['fpath'].$path.$f['ext']; if ( file_exists($file) ){ if ( !bbn\File\Dir::createPath($dest.X::dirname($data['path'])) ){ return $this->error("Impossible to create the path ".$dest.X::dirname($data['path'])); } if ( !bbn\File\Dir::copy($file, $dest.$path.$f['ext']) ){ return $this->error('Impossible to export the file '.$path.$f['ext']); } } } else { $dir = $f['fpath'].$data['path']; if ( file_exists($dir) ){ if ( !bbn\File\Dir::copy($dir, $dest.$data['path']) ){ return $this->error('Impossible to export the folder '.$data['path']); } } } } } else { $ext = bbn\Str::fileExt($data['path']); $dir = false; foreach ( $dirs[$data['dir']]['files'] as $f ){ if ( $ext === $f['ext'] ){ $dir = $f['fpath']; } } if ( !$dir ){ $dir = $dirs[$data['dir']]['files'][0]['fpath']; } $dest = $root_dest.$data['name'].'/'.$data['path']; if ( $data['type'] === 'file' ){ if ( !bbn\File\Dir::createPath(substr($dest, 0, Strrpos($dest, '/') + 1)) ){ return $this->error('Impossible to create the path ' . substr($dest, 0, Strrpos($dest, '/') + 1)); } } if ( !bbn\File\Dir::copy($dir.$data['path'], $dest) ){ return $this->error('Impossible to export the file or folder '.$data['name']); } } // Create zip file if ( class_exists('\\ZipArchive') ){ $dest = $this->isMvc($dirs[$data['dir']]) ? $root_dest.$data['name'].'/mvc/' : $dest; $filezip = BBN_USER_PATH.'tmp/'.$data['name'].'.zip'; $zip = new \ZipArchive(); if ( $err = $zip->open($filezip, \ZipArchive::OVERWRITE) ){ if ( file_exists($dest) ){ if ( ($data['type'] === 'dir') || $this->isMvc($dirs[$data['dir']]) ){ // Create recursive directory iterator $files = bbn\File\Dir::scan($dest); foreach ($files as $file){ // Add current file to archive if ( ($file !== $root_dest.$data['name']) && is_file($file) && !$zip->addFile($file, str_replace($root_dest.$data['name'].'/', '', $file)) ){ return $this->error("Impossible to add $file"); } } } else { if ( !$zip->addFile($dest, $data['path']) ){ return $this->error("Impossible to add $dest"); } } if ( $zip->close() ){ if ( !bbn\File\Dir::delete($root_dest, 1) ){ return $this->error("Impossible to delete the directory $root_dest"); } return $filezip; } return $this->error("Impossible to close the zip file $filezip"); } return $this->error("The path does not exist: $dest"); } return $this->error("Impossible to create $filezip ($err)"); } return $this->error("ZipArchive class non-existent"); } } return $this->error(); }

BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.