php zip

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* 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>
*
*