Domanda

I am storing .docx files in a mysql database as largeblobs, in separate chunks (so as not to overflow each blob). Then in a php, I display the document after "gluing" together the chunks from the database. Everything looks great except that the document appears not to have page breaks, which is a problem when trying to export it into other programs. Anyone know how to get the page breaks in there or where I went wrong?

<?
$username=xxx;
$password=xxx;
$database=xxx;

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");

$doc=$_GET['doc'];
header('Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
$request = mysql_query("SELECT docData FROM tblDoc WHERE doc='$doc' ORDER BY pieceOrder ASC");
while($row=mysql_fetch_array($request)) {
    echo $row['docData'];
}
mysql_close();
?>
È stato utile?

Soluzione 2

It turned out everything was being stored just fine. As you said, @pilsetnieks. It was just then when I was exporting from my app, I wasn't assigning it as the correct type so it was not expecting the formatting it got. Thanks for all your help!

Altri suggerimenti

A DOCX file is just a renamed ZIP file with a number of XML files and other assets inside. If you split the file for uploading and then reassemble it in the correct order for downloading, there should not be any differences at all from the originally uploaded file. However, if there is an error with reassembling the file, it most likely wouldn't open at all. The only way to actually remove page breaks would be to remove those particular XML tags from some of the internal XML files.

However, and this may be a long shot, there are five little icons to the bottom right of a MS Word window, to the left of the zoom slider, indicating the view you're using for viewing the document. (The same can be accessed via View -> Document Views in the ribbon.) (Specific details may vary among Word versions.) Now, the default is the first one, Print layout, then there is Full screen reading, Web layout, Outline, and Draft. Is it possible that, for documents coming from the web, your copy of Word turned on Web layout automatically? (Web layout doesn't have page breaks.)

Two more things:

  1. You should also add a Content-Disposition header to indicate that this file should be downloaded (you can also specify the filename it will be saved under there):

    $filename = 'example.docx';
    header('Content-Disposition: attachment; filename='.$filename);
    
  2. You shouldn't use mysql_ functions, they have been deprecated, they are a safety risk and they lead to unmaintainable code. You're better off with using mysqli_ or PDO for database access. More here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top