-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasurat-generatefile.php
76 lines (71 loc) · 2.61 KB
/
datasurat-generatefile.php
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
include 'setting/conn.php';
$user_role = $_GET['user_role'];
// delete all temporary file before download
// file to delete
$folder = 'file/tmp-files';
//Get a list of all of the file names in the folder.
$files = glob($folder . '/*');
//Loop through the file list.
foreach($files as $file){
//Make sure that this is a file and not a directory.
if(is_file($file)){
unlink($file);
}
}
// directory file
$dir_file = 'file/surat-masuk';
$zipname = "";
if (ISSET($_GET['pagename'])) {
$pagename = $_GET['pagename'];
$username_pengguna = $_GET['username_pengguna'];
if ($pagename == 'surat-masuk') {
// CODE HERE FOR GET ALL FILE
$zipname = 'All_File.zip';
$zip = new ZipArchive;
if ($zip->open($zipname, ZipArchive::CREATE) === TRUE){
// add file to zip
$db_getfile=$db->select("surat","*",["username_pengguna" => $username_pengguna, "hapus" => 0]) or die("<script>alert('File PDF tidak tersedia, gagal download!'); window.location = 'agenda-surat.php'</script>");
foreach ($db_getfile as $table) {
if ($table['foto_lampiran'] != "") {
$zip->addFile($dir_file.'/' . $table['foto_lampiran']);
}
}
$zip->addFile($dir_file.'/' .'readme.txt');
$zip->close();
}
} else if ($pagename == 'agenda-keluar') {
$dari_tgl = $_GET['dari_tgl'];
$sampai_tgl = $_GET['sampai_tgl'];
// create file zip
$zipname = 'Filesurat_tgl_'.$dari_tgl.'_sampai-tgl_'.$sampai_tgl.'.zip';
// if(file_exists($zipname)){
// unlink($zipname);
// }
$zip = new ZipArchive;
if ($zip->open($zipname, ZipArchive::CREATE) === TRUE){
$db_getfile=$db->select("surat","*",["username_pengguna" => $username_pengguna, "hapus" => 0,"tgl_diterima[<>]"=>[$dari_tgl,$sampai_tgl]]) or die("<script>alert('File PDF tidak tersedia, gagal download!'); window.location = 'agenda-surat.php'</script>");
foreach ($db_getfile as $table) {
if ($table['foto_lampiran'] != "") {
$zip->addFile($dir_file.'/' . $table['foto_lampiran']);
}
}
$zip->addFile($dir_file.'/' .'readme.txt');
$zip->close();
}
}
$new_zipname = 'file/tmp-files/'.$zipname;
rename($zipname, $new_zipname);
if(file_exists($new_zipname)){
//Set Headers:
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename=$new_zipname");
header('Content-Length: ' . filesize($new_zipname));
header("Location: $new_zipname");
readfile($new_zipname);
exit();
}
} else {
echo "wakwawww";
}
?>