1

In PHP I've to remove the author metadata from a DOCX file. First of all, I've unzip the document and after I've edit the author metadata setting it empty using an XML reader library.

$file = 'document.docx';
$filename = 'path/'.$file;

// Unzip the docx
$unzipped = md5($filename);

if (file_exists($unzipped)) {
    rmdir($unzipped);
    mkdir($unzipped);
}

$zip = new ZipArchive;
$res = $zip->open($filename);
if ($res === true) {
    extractFolder($zip, "word/media", $unzipped);
    $zip->extractTo($unzipped); 
    $zip->close();
} else {
    die("The docx file appears to be corrupt (i.e. it can't be opened using Zip).\n");
}

The problem occurs when I tried to re-zip the document. In fact, when the re-zip is done, the docx file seems to be corrupted when I open it in Word.

create_docx($unzipped,'_zips/'.$file );

How can I modify the author metadata (setting the document anonymous) and save the correct docx file?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
apanzett
  • 11
  • 3

1 Answers1

0

I don't know php, but I assume the problem is that you have to compress inside the folder $unzipped, NOT the folder itself. So a kind of recursive "$unzipped/*" as source instead of "$unzipped".

Jean Fontaine
  • 135
  • 1
  • 1
  • 7