79 |
$file = "daily_report_".strftime("%Y%m%d", $date).".zip"; |
$file = "daily_report_".strftime("%Y%m%d", $date).".zip"; |
80 |
|
|
81 |
$remote_file = 'cdr/'.$file; |
$remote_file = 'cdr/'.$file; |
82 |
|
|
83 |
|
$remote_size = ftp_size($conn_id, $remote_file); |
84 |
|
if ($verbose) |
85 |
|
echo "Récupération de ".$remote_size." Ko\n"; |
86 |
|
|
87 |
$local_file = DOL_DATA_ROOT.'/telephonie/CDR/temp/'.$file; |
$local_file = DOL_DATA_ROOT.'/telephonie/CDR/temp/'.$file; |
88 |
$handle = fopen($local_file, 'w'); |
$handle = fopen($local_file, 'w'); |
89 |
|
|
90 |
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) |
if (ftp_fget($conn_id, $handle, $remote_file, FTP_BINARY, 0)) |
91 |
{ |
{ |
92 |
if ($verbose) |
if ($verbose) |
93 |
echo "Le chargement a réussi dans ".$local_file."\n"; |
echo "Le chargement a réussi dans ".$local_file."\n"; |
100 |
// Fermeture du flux FTP |
// Fermeture du flux FTP |
101 |
ftp_close($conn_id); |
ftp_close($conn_id); |
102 |
|
|
103 |
// Dezippage du fichier |
$local_size = filesize($local_file); |
|
|
|
|
$zip = zip_open($local_file); |
|
104 |
|
|
105 |
if ($zip) { |
if (file_exists($local_file) && $local_size === $remote_size && $local_size > 0) |
106 |
|
{ |
107 |
while ($zip_entry = zip_read($zip)) |
// Dezippage du fichier |
108 |
{ |
$zip = zip_open($local_file); |
109 |
if ($verbose) |
|
110 |
{ |
if ($zip) { |
111 |
echo "Nom du fichier : " . zip_entry_name($zip_entry) . "\n"; |
|
112 |
echo "Taille réelle : " . zip_entry_filesize($zip_entry) . "\n"; |
while ($zip_entry = zip_read($zip)) |
113 |
echo "Taille compressée : " . zip_entry_compressedsize($zip_entry) . "\n"; |
{ |
114 |
echo "Méthode : " . zip_entry_compressionmethod($zip_entry) . "\n"; |
if ($verbose) |
115 |
} |
{ |
116 |
|
echo "Nom du fichier : " . zip_entry_name($zip_entry) . "\n"; |
117 |
if (zip_entry_open($zip, $zip_entry, "r")) |
echo "Taille réelle : " . zip_entry_filesize($zip_entry) . "\n"; |
118 |
{ |
echo "Taille compressée : " . zip_entry_compressedsize($zip_entry) . "\n"; |
119 |
if ($verbose) |
echo "Méthode : " . zip_entry_compressionmethod($zip_entry) . "\n"; |
120 |
echo "Decompression dans ".DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry)."\n"; |
} |
121 |
|
|
122 |
$fp = fopen(DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry),"w"); |
if (zip_entry_open($zip, $zip_entry, "r")) |
123 |
|
{ |
124 |
if ($fp) |
if ($verbose) |
125 |
{ |
echo "Decompression dans ".DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry)."\n"; |
126 |
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
|
127 |
|
$fp = fopen(DOL_DATA_ROOT.'/telephonie/CDR/atraiter/'.zip_entry_name($zip_entry),"w"); |
128 |
if (fwrite($fp, $buf) === FALSE) |
|
129 |
{ |
if ($fp) |
130 |
echo "Erreur d'ecriture\n"; |
{ |
131 |
} |
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); |
132 |
fclose($fp); |
|
133 |
} |
if (fwrite($fp, $buf) === FALSE) |
134 |
zip_entry_close($zip_entry); |
{ |
135 |
} |
echo "Erreur d'ecriture\n"; |
136 |
} |
} |
137 |
zip_close($zip); |
fclose($fp); |
138 |
|
} |
139 |
|
zip_entry_close($zip_entry); |
140 |
|
} |
141 |
|
} |
142 |
|
zip_close($zip); |
143 |
|
} |
144 |
|
|
145 |
|
// Archivage du fichier |
146 |
|
|
147 |
|
} |
148 |
|
else |
149 |
|
{ |
150 |
|
print "Erreur de récupération du fichier ".$local_file."\n"; |
151 |
|
print "Remote size ".$remote_size."\n"; |
152 |
|
print "Local size ".$local_size."\n"; |
153 |
} |
} |
|
|
|
|
// Archivage du fichier |
|
154 |
|
|
155 |
if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/archive/')) |
if (!file_exists(DOL_DATA_ROOT.'/telephonie/CDR/archive/')) |
156 |
{ |
{ |