php zip

HYEONG HWAN, MUN/ 9월 6, 2023/ 미분류/ 0 comments

https://blog.lael.be/post/11818

/* CONFIG */
$zipfileName = $_POST['html-file-name'];
if($zipfileName == ''){
  $zipfileName = 'custom-admin';
}


$filename = "../your-custom-admin/".$zipfileName.".zip"; //use the /tmp folder to circumvent any permission issues on the root folder

/* END CONFIG */
	

$zip = new ZipArchive();

$zip->open($filename, ZipArchive::CREATE);


foreach( $_POST['pages'] as $page=>$content ) {

  $page = $_POST['html-file-name'];
  if($page == ''){
    $page = 'custom-admin';
  }

	$zip->addFromString($page.".html", $_POST['doctype']."\n".stripslashes($content));

}
	
$zip->close();


if ($zip->open($filename, ZipArchive::CREATE) === TRUE) {
    $zip->extractTo('../your-custom-admin/');
    $zip->close();

} 


$yourfile = $filename;

$file_name = basename($yourfile);

header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Length: " . filesize($yourfile));

readfile($yourfile);

unlink($filename);

exit;

Leave a Comment

작성하신 댓글은 관리자의 수동 승인 후 게시됩니다.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*