method export documentation in bbn\Ide\Directories
Exports a file or a directory, normal or MVC.
function($dir, $path, $name, $type = 'file')
{
($root = $this->getRootPath($dir)) &&
\defined('BBN_USER_PATH')
){
$is_file = $type === 'file';
$wtype = $is_file ? 'file' : 'directory';
$rnd = bbn\Str::genpwd();
$root_dest = BBN_USER_PATH . 'tmp/' . $rnd . '/';
$files = [];
if ( !empty($cfg['tabs']) ){
$root_dest_mvc = $root_dest . $name . '/mvc/';
foreach ( $cfg['tabs'] as $t ){
if ( empty($t['fixed']) ){
$real = $t['path'];
if ( X::dirname($path) !== '.' ){
$real .= X::dirname($path) . '/';
}
if ( $is_file ){
foreach ( $t['extensions'] as $e ){
if ( is_file($root . $real . $name . '.' . $e['ext']) ){
$real .= $name . '.' . $e['ext'];
array_push($files, [
'src' => $root . $real,
'dest' => $root_dest_mvc . $real,
'is_file' => $is_file
]);
break;
}
}
}
else {
$real .= $name;
if ( is_dir($root . $real) ){
array_push($files, [
'src' =>$root . $real,
'dest' => $root_dest_mvc . $real,
'is_file' => $is_file
]);
}
}
}
}
}
else {
if ( file_exists($root . $path) ){
array_push($files, [
'src' => $root . $path,
'dest' => $root_dest . $path,
'is_file' => $is_file
]);
}
}
foreach ( $files as $f ){
if ( $f['is_file'] ){
if ( !bbn\File\Dir::createPath(X::dirname($f['dest'])) ){
$this->error("Impossible to create the path " . X::dirname($f['dest']));
return false;
}
}
if ( !bbn\File\Dir::copy($f['src'], $f['dest']) ){
$this->error('Impossible to export the ' . $wtype . ' ' . $f['src']);
return false;
}
}
if ( class_exists('\\ZipArchive') ){
$filezip = BBN_USER_PATH.'tmp/'.$name.'.zip';
$zip = new \ZipArchive();
if ( $err = $zip->open($filezip, \ZipArchive::OVERWRITE) ){
if ( file_exists($root_dest) ){
if ( (!$is_file) || !empty($cfg['tabs']) ){
// Create recursive directory iterator
$files = bbn\File\Dir::scan($root_dest);
foreach ($files as $file){
$tmp_dest = str_replace(
$root_dest . (empty($cfg['tabs']) ? '/' : ''),
(!empty($cfg['tabs']) ? 'mvc/' : ''),
$file
);
// Add current file to archive
if ( ($file !== $root_dest.$name) &&
is_file($file) &&
!$zip->addFile($file, $tmp_dest)
){
$this->error("Impossible to add $file");
return false;
}
}
}
else {
if ( !$zip->addFile($root_dest, $path) ){
$this->error("Impossible to add $root_dest");
return false;
}
}
if ( $zip->close() ){
if ( !bbn\File\Dir::delete(BBN_USER_PATH . 'tmp/' . $rnd, 1) ){
$this->error("Impossible to delete the directory " . BBN_USER_PATH . 'tmp/' . $rnd);
return false;
}
return $filezip;
}
$this->error("Impossible to close the zip file $filezip");
return false;
}
$this->error("The path does not exist: $root_dest");
return false;
}
$this->error("Impossible to create $filezip ($err)");
return false;
}
$this->error("ZipArchive class non-existent");
return false;
}
}
Exports a file or a directory, normal or MVC. 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.
© 2011-2025
BBN Solutions