Example #1
0
    rmdirRecursive($extractPath . DIRECTORY_SEPARATOR . 'mod_neno_dashboard');
    // Compress library
    $files = files($extractPath . DIRECTORY_SEPARATOR . 'lib_neno', true);
    $zipData = array();
    foreach ($files as $file) {
        $zipData[] = array('name' => str_replace($extractPath . DIRECTORY_SEPARATOR . 'lib_neno' . DIRECTORY_SEPARATOR, '', $file), 'file' => $file);
    }
    createZip($packagePath . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'lib_neno.zip', $zipData);
    rmdirRecursive($extractPath . DIRECTORY_SEPARATOR . 'lib_neno');
    // Compress library
    $files = files($extractPath, true);
    $zipData = array();
    foreach ($files as $file) {
        $zipData[] = array('name' => str_replace($extractPath . DIRECTORY_SEPARATOR, '', $file), 'file' => $file);
    }
    createZip($packagePath . DIRECTORY_SEPARATOR . 'pkg_neno.zip', $zipData);
    rmdirRecursive($packagePath . DIRECTORY_SEPARATOR . 'packages');
    unlink($packagePath . DIRECTORY_SEPARATOR . 'pkg_neno.xml');
    unlink($packagePath . DIRECTORY_SEPARATOR . 'script.php');
}
function folders($path)
{
    $it = new DirectoryIterator($path);
    $folders = array();
    while ($it->valid()) {
        if (is_dir($it->getPathname()) && !$it->isDot() && $it->getFilename() != '.git') {
            $folders[] = $it->getFilename();
        }
        $it->next();
    }
    return $folders;
 function backup_extension($moduleInfo)
 {
     $backup_created = false;
     global $application;
     $modname = $moduleInfo->name;
     if (!$this->isExtensionInstalled($modname)) {
         return;
     }
     modApiFunc('Modules_Manager', 'includeAPIFileOnce', $modname);
     $extensiondir = $application->getAppIni('PATH_ADD_MODULES_DIR') . "/" . strtolower($modname);
     $backupdir = $application->getAppIni('PATH_BACKUP_DIR');
     $getAllExtensionTables = array_keys($modname::getTables());
     /*Backup DB tables for extensions - start */
     $db_backup = backupDB_tables($extensiondir, $modname . "_" . date("Y-m-d") . ".sql", $getAllExtensionTables);
     if ($db_backup) {
         $backup_created = createZip($extensiondir, $backupdir, $modname . '_' . date('Y-m-d') . '.zip', array());
     }
     return $backup_created;
 }
/**
 * Get the metric results for the named metric(s) for the data from the given url
 * The data will be fetched from the url and zipped before being sent.
 * @param $url the url for the data to process
 * @param $requests the request for getting metrics (correctly formatted to send)
 * @param $timeout the length of time the metrics server should cache the data for in seconds. Default to 60
 * @return false, if the call failed, else the response data from the call (will be a json string).
 */
function getMetricsUsingZip($url, $requests, $timeout = 60)
{
    global $CFG;
    $str = file_get_contents($url);
    $time = time();
    $zipfilepath = $CFG->dirAddress . "map_" . $time . ".zip";
    $zip = createZip($zipfilepath, $str);
    if ($zip) {
        return callAnalyticsAPIWithZip('POST', $requests, $zipfilepath, $timeout);
    } else {
        return "";
    }
}
Example #4
0
 * create array of filenames in /home/tmp dir
 */
$dirhandler = opendir($config_temp_dir);
$nofiles = 0;
while ($file = readdir($dirhandler)) {
    // if $file isn't this directory or its parent
    // add to the $file_names array
    if ($file != '.' && $file != '..') {
        $nofiles++;
        $file_names[$nofiles] = $config_temp_dir . $file;
    }
}
//close the handler
closedir($dirhandler);
/**
 * add all.zip files (array from above readdir) in /home/tmp to zip and create zip in /home/backups
 * below is a private function in functions file
 */
createZip($file_names, $fullBackupFile, true);
/**
 * delete all .zip files in /home/rconfig/tmp
 */
foreach ($file_names as $file) {
    unlink($file);
}
if (file_exists($fullBackupFile)) {
    $response = json_encode(array('success' => true));
} else {
    $response = json_encode(array('failure' => true));
}
echo $response;
Example #5
0
 function downloadZip()
 {
     createZip($dir, $zipfilename, true);
 }
Example #6
0
 public function downloadCrate()
 {
     if ($this->myauth->getUserId() == 1) {
         $data['isPaid'] = true;
     } else {
         $data['isPaid'] = Am_Lite::getInstance()->checkPaid();
     }
     if (!$data['isPaid']) {
         return false;
     }
     $this->load->helper('string');
     $files = array();
     $slugs = array();
     foreach ($_SESSION['crate']['video'] as $key => $val) {
         foreach ($val as $k => $v) {
             array_push($files, $v);
             array_push($slugs, $k);
         }
     }
     foreach ($_SESSION['crate']['song'] as $key => $val) {
         foreach ($val as $k => $v) {
             array_push($files, $v);
             array_push($slugs, $k);
         }
     }
     function createZip($files, $zip_file)
     {
         $zip = new ZipArchive();
         if ($zip->open($zip_file, ZipArchive::OVERWRITE) === TRUE) {
             foreach ($files as $file) {
                 $file = str_replace("../assets", $_SERVER['DOCUMENT_ROOT'] . "/assets", $file);
                 if (!file_exists($file)) {
                     die($file . ' does not exist');
                 }
                 if (!is_readable($file)) {
                     die($file . ' not readable');
                 }
                 $path = explode("/", $file);
                 $fileName = $path[sizeof($path) - 1];
                 $zip->addFile($file, $fileName);
             }
             $zip->close();
             $_SESSION['cart'] = array();
             $_SESSION['cart']['video'] = array();
             $_SESSION['cart']['song'] = array();
             return true;
         } else {
             return false;
         }
     }
     $temp = time() . '.zip';
     $zip_name = $temp;
     if (createZip($files, $zip_name)) {
         session_write_close();
         if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $zip_name)) {
             header('Location: ' . base_url() . $zip_name);
         } else {
             $dir = $_SERVER['DOCUMENT_ROOT'] . '/';
             $name = explode(".", $zip_name);
             $name_of_zip = $name[0];
             $root = scandir($dir);
             foreach ($root as $value) {
                 if ($value === '.' || $value === '..') {
                     continue;
                 }
                 if (is_file($dir . $value)) {
                     $extension = explode(".", $dir . $value);
                     $ext = end($extension);
                     if ($ext == 'zip' || $ext == 'php' || $ext == 'htaccess') {
                         continue;
                     } else {
                         $created_zip_name = $extension[0];
                         if ($created_zip_name == $name_of_zip) {
                             rename($dir . $value, $dir . $zip_name);
                             header('Location: ' . base_url() . $zip_name);
                         }
                     }
                 }
             }
         }
         exit;
     } else {
         exit;
     }
 }
Example #7
0
        foreach ($valid_files as $file) {
            $zip->addFile($file, $file);
        }
        // debug
        // echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
        // close the zip -- done!
        $zip->close();
        // check to make sure the file exists
        return file_exists($destination);
    } else {
        return false;
    }
}
// end createZip;
// startZipping:
$resultOfZipCreation = createZip($fileToZip, $backupFileName);
// end startZipping;
// sendMail:
if ($resultOfZipCreation) {
    $fileatt = $backupFileName;
    // Path to the file.
    $fileatt_type = "application/zip";
    // File Type
    $fileatt_name = $backupFileName;
    // Filename that will be used for the file as the attachment
    $file = fopen($fileatt, 'rb');
    $data = fread($file, filesize($fileatt));
    fclose($file);
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers = "From: {$mailFrom}";