private function zipNotDups() { $aFiles = array(); $results = $this->getNotDups(); while ($row = mysql_fetch_assoc($results)) { array_push($aFiles, $this->extractTo . $row['file_name']); } return create_zip($aFiles, $this->extractTo . $this->userId . '.zip', true, false); }
public static function shareOnMarket(&$market) { $cibDir = dirname(__FILE__) . '/../../../../' . config::byKey('userScriptDir', 'script') . '/' . $market->getLogicalId(); if (!file_exists($cibDir)) { throw new Exception('Impossible de trouver le script :' . $cibDir); } $tmp = dirname(__FILE__) . '/../../../../tmp/' . $market->getLogicalId() . '.zip'; if (!create_zip($cibDir, $tmp)) { throw new Exception('Echec de création du zip. Répertoire source : ' . $cibDir . ' / Répertoire cible : ' . $tmp); } return $tmp; }
public static function shareOnMarket(&$market) { $informations = explode('.', $market->getLogicalId()); $cibDir = realpath(dirname(__FILE__) . '/../template/' . $informations[0] . '/cmd.' . $informations[1] . '.' . $informations[2] . '.' . $informations[3] . '.html'); if (!file_exists($cibDir)) { throw new Exception('Impossible de trouver le widget ' . $cibDir); } $tmp = dirname(__FILE__) . '/../../../../tmp/' . $market->getLogicalId() . '.zip'; if (!create_zip($cibDir, $tmp)) { throw new Exception('Echec de création du zip. Répertoire source : ' . $cibDir . ' / Répertoire cible : ' . $tmp); } return $tmp; }
function create_zip($folder, $files, $destination, $msg = false, $zip = null) { if (!function_exists('zip_open')) { MSGError("Zip file error -- zip not installed (" . getFunctionName() . ")"); LogError("Zip file error -- zip not installed (" . getFunctionName() . ")"); } $ds = DIRECTORY_SEPARATOR; if ($ds == "") { $ds = "/"; } $dest = null; if ($zip == null) { $zip = new ZipArchive(); if ($zip->open($destination, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { return -1; } $dest = $destination; $destination = '.'; } foreach ($files as $file) { if ($msg) { echo "Packing file " . $file . "\n"; } if (($pos = strrpos($file, $ds)) !== false) { $file = substr($file, $pos + 1); } if (is_dir($folder . $ds . $file) === true) { $zip->addEmptyDir($file); create_zip($folder . $ds . $file, glob($folder . $ds . $file . $ds . '*'), $file, $msg, $zip); } else { if (is_file($folder . $ds . $file) === true) { $zip->addFile($folder . $ds . $file, $destination . $ds . $file); } } } if ($dest != null) { $zip->close(); if (file_exists($dest)) { return 1; } else { return 0; } } else { return 1; } }
function export_zip($tables, $output_file) { $output_folder = sys_get_temp_dir() . "/openbiblio_export"; if (!file_exists($output_folder)) { mkdir($output_folder); } foreach ($tables as $table) { create_csv($table, $output_folder); } $output_file = sys_get_temp_dir() . "/" . $output_file; $files = scandir($output_folder); if (create_zip($files, $output_folder, $output_file, true)) { header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename={$output_file}"); header("Content-Transfer-Encoding: binary"); readfile($output_file); } else { print "Cannot export a zipped file."; } }
{ header("Content-Disposition: attachment; filename=\"" . $fname . "\""); header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: binary"); } // *** we need to "exit()" executed options *** // // *** else we might output also the trailling content *** // if (isset($_GET['cleancache'])) { clean_cache(); echo "Done"; exit; } if (isset($_POST['createzip'])) { $zpath = zip_path(); if (!file_exists($zpath) || !_CACHE) { create_zip($zpath); // If no cache we need to forward the temp zip path // for the chained ajax request if (!_CACHE) { header('Content-Type: application/json'); echo json_encode(array('zip' => basename($zpath))); } } exit; } if (isset($_GET['zip'])) { if (_CACHE) { $zpath = zip_path(); } else { // use basename to avoid path injection // Note: sys_get_temp_dir drops any trailling slash
<?php include "incl/functions.php"; include "incl/config.php"; if ($do_file_download) { //create zip file $selected_file_paths = array(); foreach ($_REQUEST['selected_files'] as $selected_file) { $selected_file_path = $save_dir . basename($selected_file); if (is_readable($selected_file_path)) { array_push($selected_file_paths, $selected_file_path); } } $zipfile_path = $temp_dir . 'scanned_' . time() . '.zip'; if (sizeof($selected_file_paths) > 0) { create_zip($selected_file_paths, $zipfile_path, true); if (is_readable($zipfile_path)) { //output path to created file echo $zipfile_path; } } } /* creates a compressed zip file */ function create_zip($files = array(), $destination = '', $overwrite = false) { //if the zip file already exists and overwrite is false, return false if (file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array();
} function set_download_headers($O) { header("Content-Disposition: attachment; filename=\"" . $O . "\""); header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: binary"); } if (isset($_GET['cleancache'])) { clean_cache(); echo "Done"; exit; } if (isset($_POST['createzip'])) { $F = zip_path(); if (!file_exists($F) || !_CACHE) { create_zip($F); if (!_CACHE) { header('Content-Type: application/json'); echo json_encode(array('zip' => basename($F))); } } exit; } if (isset($_GET['zip'])) { if (_CACHE) { $F = zip_path(); } else { $F = sys_get_temp_dir() . '/' . basename($_GET['zip']); } set_download_headers(GNAME . ".zip"); send_file($F, 'application/zip');
$ds = DIRECTORY_SEPARATOR; //1 $storeFolder = ''; //2 if (!empty($_FILES)) { $tempFile = $_FILES['file']['tmp_name']; //3 $targetPath = dirname(__FILE__) . $ds . $storeFolder . $ds; //4 $targetFile = $targetPath . $_FILES['file']['name']; //5 $call_log_file = str_replace('-all', '', basename($targetFile)); $upload_file = $targetPath . $call_log_file; move_uploaded_file($tempFile, $upload_file); //6 $result = create_zip($upload_file, 'test.zip'); } function create_zip($files = array(), $destination = '', $overwrite = false) { //if the zip file already exists and overwrite is false, return false if (file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if (is_array($files)) { //cycle through each file foreach ($files as $file) { //make sure the file exists if (file_exists($file)) {
@file_put_contents($fname . ".tmp", base64_encode(serialize($data0))); @rename($fname . ".tmp", $fname . ".dat"); $data0 = array(); if ($level > 0) { list($score, $data0) = DBScoreSite($_SESSION["usertable"]["contestnumber"], $_SESSION["usertable"]["usersitenumber"], 1, -1); } $ct = DBGetActiveContest(); $localsite = $ct['contestlocalsite']; $fname = $remotedir . $ds . "score_site" . $localsite . "_" . $localsite . "_x"; // . md5($_SERVER['HTTP_HOST']); @file_put_contents($fname . ".tmp", base64_encode(serialize($data0))); @rename($fname . ".tmp", $fname . ".dat"); scoretransfer($fname . ".dat", $localsite); if (@create_zip($remotedir, glob($remotedir . '/*.dat'), $fname . ".tmp") != 1) { LOGError("Cannot create score zip file"); if (@create_zip($remotedir, array(), $fname . ".tmp") == 1) { @rename($fname . ".tmp", $destination); } } else { @rename($fname . ".tmp", $destination); } @fclose($fp); @unlink($destination . ".lck"); } else { if (file_exists($destination . ".lck", 'x') && filemtime($destination . ".lck", 'x') < time() - 180) { @unlink($destination . ".lck"); } } } } }
function file() { // dump out file $data = implode("", $this->datasec); $ctrldir = implode("", $this->ctrl_dir); return $data . $ctrldir . $this->eof_ctrl_dir . pack("v", sizeof($this->ctrl_dir)) . pack("v", sizeof($this->ctrl_dir)) . pack("V", strlen($ctrldir)) . pack("V", strlen($data)) . ""; // .zip file comment length } } include "plog-globals.php"; include "plog-load_config.php"; connect_db(); if (!isset($_REQUEST["checked"]) || !is_array($_REQUEST["checked"])) { echo 'No pictures were selected.'; } else { create_zip($_REQUEST["checked"], $_REQUEST["dl_type"]); } function create_zip($checked, $level) { global $zipfile; $dir = "Plogger." . date("Y.m.d") . "/"; $zipfile = new zipfile(); // add the subdirectory ... important! // $zipfile -> add_dir($dir); add_photos($checked, $level, $dir, $zipfile); // the next three lines force an immediate download of the zip file: header("Content-type: application/octet-stream"); header("Content-disposition: attachment; filename=plog-package-" . date("Y.m.d") . ".zip"); echo $zipfile->file(); return; }
require 'includes/functions.php'; include 'includes/header.php'; if ($_GET['download']) { // Zip File Name + Path Configuration $imagePath = "bebo_downloads/"; $zipPath = "zips/"; $salt = rand(9000000000, 9999999999); $zip_name = $zipPath . $salt . "_bebo_pictures.zip"; // Split out text input to seperate lines $urlArray = explode("\n", $_POST['lines']); $urlOutcome = checkURL($urlArray); if ($urlOutcome == FALSE) { // Pull images from POST into Array then generate zip file $new_pics = savePics($urlArray, $imagePath); $result = create_zip($new_pics, $zip_name); // Display success / fail message if ($result) { echo "<h1>Success!</h1>\n\t\t\t\t\t<div class=\"descr\">Your file is ready to be downloaded!</div>\n\t\t\t\t\t<p>Go <a href=\"download_images.php?filename=" . $salt . "_bebo_pictures.zip\">here</a> to retrieve it.<br /><br /><b>Note:</b> Once you have downloaded your file, it will be removed from our server immediately for security reasons. If you need to download it again please repeat the process.</p>"; } else { echo "Hmm, something didn't work quite right! Please report it to johnathan [at] weleasewodewick.com"; } // Tidy up pictures deletePics($new_pics); } else { echo "<h1>Error! :o(</h1>\n\t\t\t\t\t <div class=\"descr\">Problem with your URLs</div>\n\t\t\t\t\t <p>Oops ... one of your URL's doesn't look like a bebo.com address. Try copying and pasting from the Bebo App again. Or, if you think this is an error, email what you pasted to johnathan [at] weleasewodewick.com"; } } else { // display form to kick off the process echo "<h1>Process your images</h1>\n\t\t\t\t<div class=\"descr\">Just paste the lines of URL's into the box below, and click submit!</div>\n\t\t\t\t\t<p><b>Note:</b> This script will connect to Bebo's servers and download all the images that you specify - if you put in dozens/hundreds of pictures, expect it to take a few minutes to complete. If the page/script gives you a timeout error, consider doing half, or even quarter of your list at a time</p>\n\t\t\t\t\t<p><font color=\"#FF0000\">300 lines of images generally = a 1-3 minute download time. Zip file size of 13-15MB. In our tests 300+ images equals timeouts.</font></p>\n\t\t\t\t<form action=\"get_images.php?download=yes\" method=\"post\">\n\t\t\t\t<textarea cols=\"65\" rows=\"8\" name=\"lines\"></textarea><br />\n\t\t\t\t<input type=\"submit\">\n\t\t\t"; }
//make sure the file exists if (file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if (count($valid_files)) { //create the archive $zip = new ZipArchive(); if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files 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; } } $files_to_zip = array('add_page_step2.php', 'save_page.php', 'add_page.php'); //if true, good; if false, zip creation failed $result = create_zip($files_to_zip, 'my-archive.zip');
public static function shareOnMarket(&$market) { $informations = explode('.', $market->getLogicalId()); $tmp_dir = realpath(dirname(__FILE__) . '/../../../../tmp/') . '/' . $market->getLogicalId(); if (file_exists($tmp_dir)) { if (!rrmdir($tmp_dir)) { throw new Exception(__('Impossible de supprimer : ', __FILE__) . $tmp_dir . __('. Vérifiez les droits', __FILE__)); } } mkdir($tmp_dir); if (!file_exists($tmp_dir) || !is_dir($tmp_dir)) { throw new Exception(__('Impossible de creer : ', __FILE__) . $tmp_dir . __('. Vérifiez les droits', __FILE__)); } $cibDirs = array(); $cibDirs[0] = realpath(dirname(__FILE__) . '/../template/' . $informations[0] . '/cmd.' . $informations[1] . '.' . $informations[2] . '.' . $informations[3] . '.html'); if (!file_exists($cibDirs[0])) { throw new Exception(__('Impossible de trouver le widget ', __FILE__) . $cibDirs[0]); } if (!rcopy($cibDirs[0], $tmp_dir . '/cmd.' . $informations[1] . '.' . $informations[2] . '.' . $informations[3] . '.html', false, array(), true)) { throw new Exception(__('Impossible de copier ', __FILE__) . $cibDirs[0] . ' => ' . $tmp_dir); } $cibDirs[1] = realpath(dirname(__FILE__) . '/../template/' . $informations[0]) . '/cmd.' . $informations[1] . '.' . $informations[2] . '.' . $informations[3]; if (file_exists($cibDirs[1])) { mkdir($tmp_dir . '/cmd.' . $informations[1] . '.' . $informations[2] . '.' . $informations[3]); if (!rcopy($cibDirs[1], $tmp_dir . '/cmd.' . $informations[1] . '.' . $informations[2] . '.' . $informations[3], false, array(), true)) { throw new Exception(__('Impossible de copier ', __FILE__) . $cibDirs[1] . ' => ' . $tmp_dir); } } $tmp = dirname(__FILE__) . '/../../../../tmp/' . $market->getLogicalId() . '.zip'; if (file_exists($tmp)) { if (!unlink($tmp)) { throw new Exception(__('Impossible de supprimer : ', __FILE__) . $tmp . __('. Vérifiez les droits', __FILE__)); } } if (!create_zip($tmp_dir, $tmp)) { throw new Exception(__('Echec de création du zip. Répertoire source : ', __FILE__) . $tmp_dir . __(' / Répertoire cible : ', __FILE__) . $tmp); } return $tmp; }
chdir("photos/{$folder_name}"); } catch (Exception $e) { } $photo_list = array(); $curl = new Curl(); # get photos foreach ($_POST as $key => $value) { $response = $curl->get($value); # move file to correct directory $destination = "{$key}.jpg"; $file = fopen($destination, "w+"); fputs($file, $response->body); fclose($file); # add to photo list array $photo_list[] = $destination; } try { $zipped = create_zip($photo_list, 'facebook.zip'); } catch (Exception $e) { } if ($zipped) { # delete zipped files foreach ($photo_list as $key => $value) { unlink($value); } # on success redirect to index header('Location: /index.php?err=2&user='******'Location: /index.php?err=1'); }
public static function shareOnMarket(&$market) { $moduleFile = dirname(__FILE__) . '/../config/devices/' . $market->getLogicalId() . '.php'; if (!file_exists($moduleFile)) { throw new Exception('Impossible de trouver le widget ' . $moduleFile); } $tmp = dirname(__FILE__) . '/../../../../tmp/' . $market->getLogicalId() . '.zip'; if (!create_zip($moduleFile, $tmp)) { throw new Exception('Echec de création du zip. Répertoire source : ' . $moduleFile . ' / Répertoire cible : ' . $tmp); } return $tmp; }
foreach ($valid_files as $file => $local) { $zip->addFile($file, $local); } //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; } } $files_to_zip = array(__DIR__ . '/css/mappingstyle.css' => '/css/mappingstyle.css', __DIR__ . '/css/style.css' => '/css/style.css', __DIR__ . '/scripts/jquery.js' => '/scripts/jquery.js', __DIR__ . '/scripts/impress.js' => '/scripts/impress.js', realpath(__DIR__ . '/../output/' . $filename . '.html') => $filename . '.html'); //if true, good; if false, zip creation failed $result = create_zip($files_to_zip, $filename . '.zip'); ?> <html lang="en"> <head> <meta charset="utf-8" /> <title>impressionist - v 0.0.1.0 | Download</title> <link href='http://fonts.googleapis.com/css?family=Inika:400,700' rel='stylesheet' type='text/css'> <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet" /> <script src="../scripts/jquery.js"></script> <script src="../css/mainstyle.css"></script> <script type="text/javascript" src=" http://twitter.github.com/bootstrap/assets/js/bootstrap-button.js"></script> </head> <body> <div id="hero">
require 'config.php'; $file = $_GET['file']; if ($file == 'all') { $tmp_dir = "../tmp"; mkdir($tmp_dir); $xml = simplexml_load_file($examples_catalog) or die("Unable to load XML file!"); $filesListXml = $xml->xpath('//file'); if (!empty($filesListXml)) { $filesList = array(); foreach ($filesListXml as $fileXml) { $files_to_zip[] = "../doc/" . (string) $fileXml->attributes()->name; } } $examples_name = 'akomantoso-examples'; //if true, good; if false, zip creation failed $result = create_zip($files_to_zip, $tmp_dir, $examples_name); chmod($examples_name . '.zip', 0755); // We'll be outputting a XML header('Content-type: application/octet-stream'); header("Pragma: no-cache"); // It will be given this name header('Content-Disposition: attachment; filename="' . $examples_name . '.zip"'); // The XML source readfile($tmp_dir . "/" . $examples_name . '.zip'); } else { // We'll be outputting a XML header('Content-type: text/xml'); header("Pragma: no-cache"); // It will be given this name header('Content-Disposition: attachment; filename="' . $file . '"'); // The XML source
setcookie("password", "", time() - 3600); setcookie("host", "", time() - 3600); setcookie("db", "", time() - 3600); } } } echo '</center><br> </td></tr></table>'; } } } elseif ($action == "zip") { if (isset($_POST['zip_dir'])) { if (!isset($_POST['zip'])) { echo "<tr><td bgcolor=\"#CCCCCC\"><br><center><form action=\"\" method=\"POST\"><input type=\"hidden\" name=\"zip_dir\" value=\"" . htmlspecialchars($_POST['zip_dir']) . "\"><input type=\"hidden\" name=\"dir\" value=\"" . $dir . "\"><input type=\"hidden\" name=\"action\" value=\"zip\">Archive name:<br><input type=\"text\" name=\"archivename\"><br><br><input type=\"submit\" value=\"Create\" name=\"zip\"></form></center></td></tr>"; } else { echo "<tr><td bgcolor=\"#CCCCCC\"><br><center>"; if (create_zip($_POST['archivename'] . ".zip", $_POST['zip_dir'])) { echo "<font color=\"green\">Zip archive '" . $name_zip . "' created successfull!</font>"; } else { echo "<font color=\"green\">Zip archive '" . $name_zip . "' created with some errors!</font><br>"; for ($a = 0; $a < count($zip_error); $a++) { echo "<font color=\"red\">" . $zip_error[$a] . "</font><br>"; } } echo "<br> </center></td></tr>"; } } else { echo '<tr><td bgcolor="#CCCCCC">'; if (!isset($_POST['zip'])) { $__dir = array(); $__file = array(); foreach (glob("*") as $f) {
public function save() { $cache = cache::byKey('market::info::' . $this->getLogicalId()); if (is_object($cache)) { $cache->remove(); } $market = self::getJsonRpc(); $params = utils::o2a($this); if (isset($params['changelog'])) { unset($params['changelog']); } switch ($this->getType()) { case 'plugin': $cibDir = dirname(__FILE__) . '/../../tmp/' . $this->getLogicalId(); if (file_exists($cibDir)) { rrmdir($cibDir); } mkdir($cibDir); $exclude = array('tmp'); rcopy(realpath(dirname(__FILE__) . '/../../plugins/' . $this->getLogicalId()), $cibDir, true, $exclude, true); $tmp = dirname(__FILE__) . '/../../tmp/' . $this->getLogicalId() . '.zip'; if (file_exists($tmp)) { if (!unlink($tmp)) { throw new Exception(__('Impossible de supprimer : ', __FILE__) . $tmp . __('. Vérifiez les droits', __FILE__)); } } if (!create_zip($cibDir, $tmp)) { throw new Exception(__('Echec de création de l\'archive zip', __FILE__)); } break; default: $type = $this->getType(); if (!class_exists($type) || !method_exists($type, 'shareOnMarket')) { throw new Exception(__('Aucune fonction correspondante à : ', __FILE__) . $type . '::shareOnMarket'); } $tmp = $type::shareOnMarket($this); break; } if (!file_exists($tmp)) { throw new Exception(__('Impossible de trouver le fichier à envoyer : ', __FILE__) . $tmp); } $file = array('file' => '@' . realpath($tmp)); if (!$market->sendRequest('market::save', $params, 30, $file)) { throw new Exception($market->getError()); } $update = update::byTypeAndLogicalId($this->getType(), $this->getLogicalId()); if (!is_object($update)) { $update = new update(); $update->setLogicalId($this->getLogicalId()); $update->setType($this->getType()); } $update->setConfiguration('version', 'beta'); $update->setLocalVersion(date('Y-m-d H:i:s', strtotime('+10 minute' . date('Y-m-d H:i:s')))); $update->save(); $update->checkUpdate(); }
function create_client_config_and_send($cert_name, $config_dir, $config_file, $remote_value, $send_type, $key_dir_name) { //will need phpseclib later.... so... if (!isset($_SESSION['password'])) { start_session('certs.php?action=send_cert&type=$send_type&cert_name=$cert_name'); } $password = stripslashes(trim($_SESSION['password'])); $username = stripslashes(trim($_SESSION['username'])); if ($username == "") { $username = "******"; } $ssh = new Net_SSH2('localhost'); if (!$ssh->login($username, $password)) { exit('Login Failed'); } //Creating a default client config file //TODO have a check to make sure /etc/openvpn.conf exists.... //If none exists... then you should prolly do some checks when the webui is first launched.... duh if (!file_exists("openvpn-client-default.conf")) { create_default_client_config(); } $vpn_config = read_openvpn_config($config_dir . $config_file); extract($vpn_config); echo "Default client file exists... <br />"; echo "Now copying to new config {$cert_name}.conf<br />"; copy("openvpn-client-default.conf", "{$cert_name}.conf"); //New Conf file should exist.... Now edit specifics... if (file_exists("{$cert_name}.conf")) { $client_config = "{$cert_name}.conf"; file_put_contents($client_config, "cert " . $cert_name . ".crt" . PHP_EOL, FILE_APPEND | LOCK_EX); file_put_contents($client_config, "key " . $cert_name . ".key" . PHP_EOL, FILE_APPEND | LOCK_EX); } else { echo "Error... client config file not found?<br />"; exit; } //Finding what dir $curr_work_dir = getcwd(); echo "Copying needed files...<br />"; //Now copying all the necc. sh!t to the root folder... then zip it? tar it? idk.. prolly zip $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); $ssh->write("cd {$key_dir_name};cp {$cert_name}.key {$ca_values['1']} {$cert_name}.crt {$curr_work_dir}\n"); $result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$result}</pre>"; //HAVE to change the permissions on *.key... or php can't touch it echo "Have to change permissions on the *.key file.. or php can't touch..<br />"; $ssh->write("cd {$curr_work_dir};chmod 555 {$cert_name}.key\n"); $result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$result}</pre>"; echo str_repeat(' ', 1024 * 64); //create array of files to zip $files_to_zip = array("{$cert_name}.crt", "{$cert_name}.key", "{$ca_values['1']}", "{$cert_name}.conf"); echo "Creating zip file <b>{$cert_name}.zip</b><br />"; echo str_repeat(' ', 1024 * 64); $result = create_zip($files_to_zip, "{$cert_name}.zip", $cert_name); // unlink every other file... unlink("{$cert_name}.crt"); unlink("{$cert_name}.key"); unlink("{$ca_values['1']}"); unlink("{$cert_name}.conf"); if ($send_type == "download") { echo "<br /> Download transfer type selected!"; echo "<br />"; echo "Result:{$result}"; echo str_repeat(' ', 1024 * 64); sleep(5); // return name of zip file, will use that to generate download link return $result; exit; } if ($send_type == "scp") { if (!isset($_SESSION['password'])) { start_session('certs.php?action=send_cert&type=$send_type&cert_name=$cert_name'); } $password = stripslashes(trim($_SESSION['password'])); $username = stripslashes(trim($_SESSION['username'])); if ($username == "") { $username = "******"; } $ssh = new Net_SSH2('localhost'); if (!$ssh->login($username, $password)) { exit('Login Failed'); } echo "SCP transfer type selected!"; echo "TYPE TOO"; echo str_repeat(' ', 1024 * 64); $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); $ssh->write("cd {$curr_work_dir};scp {$cert_name}.zip {$username}@{$remote_host}:{$remote_dir}\n"); $ssh->setTimeout(10); sleep(5); $result = $ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX); echo "<pre>{$result}</pre>"; echo str_repeat(' ', 1024 * 64); exit; } }
public function __construct($uploads, $uploadDir = '../files/') { global $folder_name, $flag, $awesome_path, $file_id; //$file_id = generate_access_id(6); //echo json_encode(array('count' => '1' , 'url' => "</br>".$file_id.'/'.$file_id.".zip" , 'pass' => '')); mkdir($uploadDir . $file_id . '/'); $uploadDir = $uploadDir . $file_id . '/'; // Split the string containing the list of file paths into an array $paths = explode("###", rtrim($_POST['paths'], "###")); // Loop through files sent foreach ($uploads as $key => $current) { // Stores full destination path of file on server $this->uploadFile = $uploadDir . rtrim($paths[$key], "/."); // Stores containing folder path to check if dir later $this->folder = substr($this->uploadFile, 0, strrpos($this->uploadFile, "/")); // Check whether the current entity is an actual file or a folder (With a . for a name) if (strlen($current['name']) != 1) { // Upload current file $this->upload($current, $this->uploadFile); } } $username = $_SESSION['login_user']; $password = $_POST['password']; $password = stripslashes($password); $password = mysql_real_escape_string($password); $privacy = $_POST['privacy']; $expiry = $_POST['expiry']; $sql = "INSERT INTO files (filename,size,filetype,username,short_id,password,privacy,expiry) VALUES('{$folder_name}','NAN','folder','{$username}','{$file_id}','{$password}','{$privacy}','{$expiry}') "; mysql_query($sql) or die('Error, query failed'); create_zip($uploadDir, $file_id); if ($password != "" && $privacy == "Private") { $rpath = realpath($uploadDir); //echo "poop".$rpath."poop"; $t = '../files/' . $file_id . '/.htaccess'; $myfile = fopen($t, "w"); $txt = 'AuthName "Protected Area" AuthType Basic AuthUserFile ' . $rpath . '\\.htpasswd require valid-user'; fwrite($myfile, $txt); fclose($myfile); $myfile2 = fopen("windows_script.vbs", "w"); $txt2 = 'Dim oShell Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run "cmd /k cd/. & cd xampp/apache/bin & htpasswd.exe -c -b ' . $rpath . '\\.htpasswd user ' . $password . '& cd/. & exit "'; fwrite($myfile2, $txt2); fclose($myfile2); exec('windows_script.vbs'); } $loll = '../files/' . $file_id . '/index.php'; $file = fopen($loll, "w"); $codee = '<?php $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("ftusers", $connection); $parent = basename(dirname($_SERVER["PHP_SELF"])); $query = "SELECT * FROM files where short_id= \'$parent\' " ; $result = mysql_query($query); $row = mysql_fetch_array($result); $countt = $row[\'expiry\']; if($countt>0){ $expiryy = $row[\'expiry\'] - 1; $sql="Update files SET expiry=\'$expiryy\' where short_id= \'$parent\' "; mysql_query($sql) or die(\'Error, query failed\'); if($countt==1){ $query2 = "DELETE FROM files WHERE short_id = \'$parent\' "; $result2 = mysql_query($query2); if($row[\'expiry\']==0) unlink($file_name); echo "File has been deleted"; } mysql_close($connection); $yy = "Location: ".$parent.".zip" ; header($yy); } echo $parent."zip"?>'; fwrite($file, $codee); fclose($file); if ($password == "") { echo json_encode(array('count' => 1, 'url' => "</br>" . $file_id . '/' . $file_id . ".zip", 'pass' => '')); } else { echo json_encode(array('count' => 1, 'url' => "</br>" . $file_id . '/' . $file_id . ".zip", 'pass' => "</br>Your password is" . $password)); } }
function create_backup($lab_config_id) { $lab_config = LabConfig::getById($lab_config_id); $site_name = $lab_config->name; $site_name = str_replace(" ", "-", $site_name); $timestamp = date("Ymd-hi"); $file_list1 = array(); # dbdir/blis_xxx $file_list2 = array(); # dbdir/blis_revamp $file_list3 = array(); # htdocs/langdata $dir_name = "../../dbdir/blis_" . $lab_config_id; $count = 0; if ($handle = opendir($dir_name)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list1[] = $dir_name . "/{$file}"; $count++; print $dir_name . "/{$file}"; } print "\n number of files"; print $count; $dir_name = "../../dbdir/blis_revamp"; if ($handle = opendir($dir_name)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list2[] = $dir_name . "/{$file}"; } $dir_name = "../../locale/langdata"; if ($handle = opendir($dir_name)) { while (false !== ($file = readdir($handle))) { if ($file === "." || $file == "..") { continue; } $file_list3[] = $dir_name . "/{$file}"; } $zip_file_name = $site_name . "_" . $timestamp . ".zip"; $result = create_zip($file_list1, $file_list2, $file_list3, $zip_file_name, true, $lab_config_id); } } } # Send file stream to user for download $file = $zip_file_name; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); unlink($file); }
// ONLY WORKS IN LINUX!!! system('stty -echo'); $password3 = trim(fgets(STDIN)); system('stty echo'); if ($password3 != $password2) { echo "\nPasswords mismatch - aborting\n"; exit; } } if (strlen($password2) < 12) { echo "\n\n#\n##\n###\n####\n#####\n###### WARNING: the main password should be really secure - consider using a longer and complicated password\n"; } $password1 = randstr(16); if (is_dir(trim($argv[1]))) { echo "Creating file " . $argv[2] . " from directory/file " . $argv[1] . "\n"; if (($ret = create_zip(trim($argv[1]), glob(trim($argv[1]) . $ds . '*'), trim($argv[2]), true)) > 0) { echo "ZIP Success\n"; } else { echo "ZIP Error {$ret}\n"; } $encdata = encryptData(file_get_contents(trim($argv[2])), '#####' . $password1, false); if ($encdata == '') { $encdata = file_get_contents(trim($argv[2])); } } else { $encdata = encryptData(file_get_contents(trim($argv[1])), '#####' . $password1, true); if ($encdata == '') { $encdata = file_get_contents(trim($argv[1])); } } file_put_contents(trim($argv[2]), $encdata);
function fullexportspecial() { global $tbl_session, $tbl_session_course, $export; $FileZip = create_zip(); $to_group_id = 0; $code_course = ''; $list_course = array(); $zip_folder = new PclZip($FileZip['TEMP_FILE_ZIP']); $list_course = CourseManager::get_course_list(); $tbl_document = Database::get_course_table(TABLE_DOCUMENT); $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $groupCondition = " props.to_group_id = {$to_group_id}"; if (empty($to_group_id)) { $groupCondition = " (props.to_group_id = 0 OR props.to_group_id IS NULL)"; } if (count($list_course) > 0) { foreach ($list_course as $_course) { if ($FileZip['PATH'] == '/') { $querypath = ''; // to prevent ...path LIKE '//%'... in query } else { $querypath = $FileZip['PATH']; } $course_id = $_course['real_id']; //Add tem to the zip file course $sql = "SELECT path FROM {$tbl_document} AS docs, {$tbl_property} AS props\n WHERE props.tool='" . TOOL_DOCUMENT . "'\n AND docs.id=props.ref\n AND docs.path LIKE '" . $querypath . "/%'\n AND docs.filetype='file'\n AND (docs.session_id = '0' OR docs.session_id IS NULL)\n AND props.visibility<>'2'\n AND {$groupCondition}\n AND docs.c_id = {$course_id}\n AND props.c_id = {$course_id}"; $query = Database::query($sql); while ($rows_course_file = Database::fetch_assoc($query)) { $rows_course_file['path']; $zip_folder->add($FileZip['PATH_COURSE'] . $_course['directory'] . "/document" . $rows_course_file['path'], PCLZIP_OPT_ADD_PATH, $_course['directory'], PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'] . $_course['directory'] . "/document" . $FileZip['PATH_REMOVE']); } //Add tem to the zip file session course $code_course = $_course['code']; $sql_session = "SELECT s.id, name, c_id\n FROM {$tbl_session_course} sc\n INNER JOIN {$tbl_session} s\n ON sc.session_id = s.id\n WHERE c_id = '{$course_id}' "; $query_session = Database::query($sql_session); while ($rows_session = Database::fetch_assoc($query_session)) { $session_id = $rows_session['id']; $sql_session_doc = "SELECT path FROM {$tbl_document} AS docs, {$tbl_property} AS props\n WHERE props.tool='" . TOOL_DOCUMENT . "'\n AND docs.id=props.ref\n AND docs.path LIKE '" . $querypath . "/%'\n AND docs.filetype='file'\n AND docs.session_id = '{$session_id}'\n AND props.visibility<>'2'\n AND {$groupCondition}\n AND docs.c_id = {$course_id}\n AND props.c_id = {$course_id} "; $query_session_doc = Database::query($sql_session_doc); while ($rows_course_session_file = Database::fetch_assoc($query_session_doc)) { $zip_folder->add($FileZip['PATH_COURSE'] . $_course['directory'] . '/document' . $rows_course_session_file['path'], PCLZIP_OPT_ADD_PATH, $_course['directory'] . "/" . $rows_session['name'], PCLZIP_OPT_REMOVE_PATH, $FileZip['PATH_COURSE'] . $_course['directory'] . '/document' . $FileZip['PATH_REMOVE']); } } } $name = rename_zip($FileZip); if ($name === false) { $export = false; return false; } else { $export = true; return $name; } } else { Display::display_error_message(get_lang('ErrorMsgSpecialExport')); //main API $export = false; return false; } }
public static function shareOnMarket(&$market) { $moduleFile = dirname(__FILE__) . '/../config/scenario/' . $market->getLogicalId() . '.json'; if (!file_exists($moduleFile)) { throw new Exception('Impossible de trouver le fichier de configuration ' . $moduleFile); } $tmp = dirname(__FILE__) . '/../../tmp/' . $market->getLogicalId() . '.zip'; if (file_exists($tmp)) { if (!unlink($tmp)) { throw new Exception(__('Impossible de supprimer : ', __FILE__) . $tmp . __('. Vérifiez les droits', __FILE__)); } } if (!create_zip($moduleFile, $tmp)) { throw new Exception(__('Echec de création du zip. Répertoire source : ', __FILE__) . $moduleFile . __(' / Répertoire cible : ', __FILE__) . $tmp); } return $tmp; }
<?php include_once ('../../../../../wp-load.php'); include_once (PARENT_DIR . '/includes/data_management/pclzip.lib.php'); $file_counter = 0; $all_file = 0; if (isset($_GET["theme_folder"])){ $theme_folder = $_GET["theme_folder"]; } create_zip ($theme_folder); function create_zip ($themeName){ global $all_file; $all_themes_dir = str_replace('\\', '/', get_theme_root()); $backup_dir = str_replace('\\', '/', WP_CONTENT_DIR).'/themes_backup'; $zip_name = $backup_dir.$themeName.'.zip'; $file_string = scan_dir($all_themes_dir.$themeName, array('.', '..', '.svn', 'thumbs.db')); $all_file = substr_count($file_string, ","); if(!is_dir($backup_dir)){ if(mkdir($backup_dir, 0700)){ $htaccess_file = fopen($backup_dir.'/.htaccess', 'a'); $htaccess_text = 'deny from all'; fwrite($htaccess_file, $htaccess_text); fclose($htaccess_file); } } $zip = new PclZip($zip_name); if ($zip->create($file_string, PCLZIP_OPT_REMOVE_PATH, $all_themes_dir.$themeName) == 0) { die("Error : ".$zip->errorInfo(true));
<?php require 'lib/bk_zip.php'; /* include zip lib */ require 'lib/bk_db.php'; /*include export code lib*/ $name_zip_file .= date("j-n-Y"); /* get date now */ $name_zip_file .= '-user.zip'; $files_to_zip = directoryToArray('../public_html', true); /*Export DB*/ backup_tables('db_host', 'user_db', 'user_db_pass', 'db_name'); /*Zip file*/ $result = create_zip($files_to_zip, $name_zip_file); /*Transfer file via FTP */ $server = 'IP FTP'; $ftp_user_name = "Username FTP"; $ftp_user_pass = "******"; $connection = ftp_connect($server); $login = ftp_login($connection, $ftp_user_name, $ftp_user_pass); if (!$connection || !$login) { die('Connection attempt failed!'); } $upload = ftp_put($connection, $name_zip_file, $name_zip_file, FTP_ASCII); if (!$upload) { echo 'FTP upload failed!'; } ftp_close($connection); /*Delete file zip and sql after backup*/ $files_db = glob("*.sql"); foreach ($files_db as $file_db) {
$this->ctrl_dir[] = $cdrec; } // dump out file function file() { $data = implode("", $this->datasec); $ctrldir = implode("", $this->ctrl_dir); return $data . $ctrldir . $this->eof_ctrl_dir . pack("v", sizeof($this->ctrl_dir)) . pack("v", sizeof($this->ctrl_dir)) . pack("V", strlen($ctrldir)) . pack("V", strlen($data)) . ""; // .zip file comment length } } connect_db(); if (!isset($_REQUEST['checked']) || !is_array($_REQUEST['checked'])) { echo 'No pictures were selected.'; } else { create_zip($_REQUEST['checked'], $_REQUEST['dl_type']); } close_db(); function create_zip($checked, $level) { global $zipfile; $dir = 'Plogger.' . date('Y.m.d') . '/'; $zipfile = new zipfile(); // add the subdirectory ... important! // $zipfile -> add_dir($dir); add_photos($checked, $level, $dir, $zipfile); $output = $zipfile->file(); // the next lines attempt to clear the cache, get the filesize, and force an immediate download of the zip file: header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
$type = $_FILES["files"]["type"][$i]; $username = '******'; $password = $_POST['password']; $password = stripslashes($password); $password = mysql_real_escape_string($password); $privacy = $_POST['privacy']; if ($password == "") { $pass_flag = 0; } else { $pass_flag = 1; } $sql = "INSERT INTO files (filename,size,filetype,username,short_id,password,privacy) VALUES('{$name}','{$size}','{$type}','{$username}','{$file_id}','{$password}','{$privacy}') "; mysql_query($sql) or die('Error, query failed'); } } create_zip($dir . $file_id . '/', $file_id); if ($pass_flag == 1 && $privacy == "Private") { $rpath = realpath($dir . $file_id . '/'); //echo "poop".$rpath."poop"; $t = '../files/' . $file_id . '/.htaccess'; $myfile = fopen($t, "w"); $txt = 'AuthName "Protected Area" AuthType Basic AuthUserFile ' . $rpath . '\\.htpasswd require valid-user'; fwrite($myfile, $txt); fclose($myfile); $myfile2 = fopen("windows_script.vbs", "w"); $txt2 = 'Dim oShell Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run "cmd /k cd/. & cd xampp/apache/bin & htpasswd.exe -c -b ' . $rpath . '\\.htpasswd user ' . $password . '& cd/. & exit "';