Created
September 26, 2012 09:37
-
-
Save kathangeorg/3787040 to your computer and use it in GitHub Desktop.
bash zip download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( $_POST['action'] == 'save' ) { | |
if ( isset( $_POST['save_pdf'] ) ) { | |
foreach ( $_POST['save_pdf'] as $save_idart ) { | |
generate_pdf_file ( $save_idart, $save_to_disc=true ); | |
} | |
//*** | |
set_time_limit(1800); // run max for 30min | |
$debug = true; | |
if ( $_POST['action'] == 'save' ) { | |
$document_root = $_SERVER['DOCUMENT_ROOT']; | |
$dirname = $document_root.'/upload/presse_pdf/'; | |
if ( $debug == true ) { print($dirname.'<br>'); } | |
for ($i=0;$i < count($_POST['save_pdf']);$i++) { | |
$_POST['save_pdf'][$i] = 'presse_'.basename($_POST['save_pdf'][$i]).'.pdf'; | |
} | |
if ( $debug == true ) { | |
print('<pre>'); | |
print_r($_POST['save_pdf']); | |
print('</pre>'); | |
} | |
$implodeFiles = implode(" ", $_POST['save_pdf']); | |
if ( $debug == true ) { print($implodeFiles.'<br>'); } | |
$tarName = 'save_pdf-'.date('d-m-Y_H-i').'.zip'; | |
// script in directory 'upload/php' therefor we need to 'cd ..' first /////cd .. && | |
$shellBefehl = "cd upload/presse_pdf/ && zip -r $tarName $implodeFiles"; | |
if ( $debug == true ) { print($shellBefehl.'<br>'); } | |
exec($shellBefehl,$var); | |
if ( $debug == true ) { | |
print('<pre>'); | |
print_r($var); | |
print('</pre>'); | |
} | |
// Header für Download senden | |
//header("HTTP/1.1 200 OK"); | |
//header("Content-Type: application/force-download"); | |
//header('Content-Disposition: attachment; filename="Zip-File-Name.zip"'); | |
//header("Content-Transfer-Encoding: binary"); | |
// Zip File senden | |
//echo $zip->file(); | |
//readfile($dir.$file); | |
//print($document_root); | |
$file = $dirname.$tarName; | |
print($file); | |
if (file_exists($file)) | |
{ | |
$zipfile = $file; | |
// http headers for zip downloads | |
header("Pragma: public"); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Cache-Control: public"); | |
header("Content-Description: File Transfer"); | |
header("Content-type: application/octet-stream"); | |
header("Content-Disposition: attachment; filename=\"".$tarName."\""); | |
header("Content-Transfer-Encoding: binary"); | |
header("Content-Length: ".filesize($zipfile)); | |
//ob_end_flush(); | |
while (ob_get_level()) { | |
ob_end_clean(); | |
} | |
@readfile($zipfile); | |
//header('Content-type: application/zip'); | |
//header('Content-Disposition: attachment; filename="' . basename($file) . '"'); | |
//readfile($zipfile); | |
unlink($zipfile); | |
exit; | |
} | |
echo "<h1>Content error</h1><p>The file does not exist!</p>"; | |
} else { | |
echo "<h1>Content error</h1><p>Please choose at least one File!</p>"; | |
} | |
//*** | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment