Сжатие ZipArchive для создания файла ODTPhp

Кемеровские программисты php общаются здесь
Anonymous
Сжатие ZipArchive для создания файла ODT

Сообщение Anonymous »

Я пытаюсь создать файл ODT в PHP с помощью ZipArchive(). Он создает поврежденный файл ODT (ccorrupted.odt). Если я изменю расширение созданного файла на zip (corrupted.zip), разархивирую его с помощью 7zip и снова заархивирую, файл станет идеальным. В чем может быть проблема ? Поврежденный файл можно получить по адресу https://cientistaspatentes.com.br/siner ... rupted.odt
Изображение

function create_zip($files = array(),$destination = '',$files2 = array(),$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
//if(file_exists($file)) {
$valid_files[] = $file;
//}
}
}

//print_r($valid_files);exit();
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
//echo "
";
//echo "destination - ".$destination."
";
//echo "overwrite - ".$overwrite."
";

if($zip->open($destination,ZIPARCHIVE::CREATE) !== true) {
return false;
}
// if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
// return false;
// }
//add the files
//echo "
";
//print_r($valid_files);
$i=0;
foreach($valid_files as $file) {
$file_n=$file;
if (strrpos($file,'/')) {
//echo 'Oi '.strrpos($file,'/').' '.substr($file,strrpos($file,'/')+1).' '.$file.'
';
$file_n=substr($file,strrpos($file,'/')+1);
}
//echo $file_n.' ';
//echo $zip->addFile($file,$file_n);

$auxF = file_get_contents($file);
if (!(file_exists($file)))
{
$msg_erro = "Erro em compactador.loc.php linha 136. $file ";
//enviar_email('gerente',$msg_erro,$habilitar_email);
echo "$msg_erro
";
}
$zip->addFromString($files2[$i],$auxF);
//echo '
';
$i++;
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status.'
';

//close the zip -- done!
$zip->close();
//echo "fim";exit();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}


Подробнее здесь: https://stackoverflow.com/questions/783 ... n-odt-file

Вернуться в «Php»