Jump to content

Recommended Posts

Dear friends,

 

I am trying to build a PHP graph using the GD library on the students' grades.  The grades files must be in a word format and in this case docx. And the docx files are archived in a zip archive basically. So what I am trying to do is to open this docx file in the zip archive, read its contents do the calculations and display the graph. The problem occurs when trying to read the docx file the result is just gibberish.

 

Here is the code I have written to open the file. It is taken from W3schools.

 

<?php
$zip = zip_open("grade.zip");

if ($zip)
  {
  while ($zip_entry = zip_read($zip))
    {
    echo "<p>";
    echo "Name: " . zip_entry_name($zip_entry) . "<br />";

    if (zip_entry_open($zip, $zip_entry))
      {
      echo "File Contents:<br/>";
      $contents = zip_entry_read($zip_entry);
      echo "$contents<br />";
      //zip_entry_close($zip_entry);
      }
    echo "</p>";
  }

}

?>

 

And here is the result:

 

Name: Test assignment.docx

File Contents:

PK! $????[Content_Types].xml ?( ??MO?@??&??W?z0?? ??M???.C??~dg???JK???Z???2???3??J??<*kR?Oz,#m??,e?????E??Di ?l ?F???t?#?6??"w?9????:0t?[?E [??N?1~???piM?Pi???r1/C4^????C?,??_??R&?+??H??d?\??CB??w?P???V????????*?h"|x?0????gV?5???i??y?$4????V"e??9?B??A???)j???T(?y?>vw?????v?(?SL???qW??U?DX???Q??w??4S?^? ??0?F?"??\?gsld?Y?dL?uH????????c9>(hVD?5??{?????A???7?t? ??PK!???N_rels/.rels ?(

 

 

Please tell me what I am doing wrong so that the contents of the file are displayed so nasty.

 

Thank you!

 

Best Regards

Stefany

A docx file is itself a ZIP file which you would have to open and then extract information out of.  There are libraries out there for working with word documents, you will probably want to look into one of them so that you are properly interpreting the docx format.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.