Jump to content

Generate Word Document from PHP


kensington

Recommended Posts

I have a PHP web page that has a web link where I click on the web link (called myPage.php) and it pulls up a Word Document Report that displays Oracle Database records and it works great if the records are under 25 records.  If over 25 then the Word Document comes up blank.  The records are very small and cant figure out why it wont work if over 25 records.

 

Here is my PHP code to pull up the Word Doc in myPage.php:

<?php 
  $fname="report.doc"; 
    $handle = fopen( $fname, "rb" ); 
    $buf = fread( $handle, filesize( $fname )); 
    fclose( $handle ); 
    $len = strlen( $buf ); 
    header( "Pragma: public" ); 
    header( "Cache-Control: private" ); 
    header( "Connection: close" ); 
    header( "Content-Type: application/msword" ); 
    header( "Content-Length: $len" ); 
    header( "Content-Disposition: inline; filename=\"$fname\"" ); 
    print $buf; 
?>
<table border="1"> 
<tr> 
<td>FieldOneHeader</td> 
<td>FieldTwoHeader</td> 
<td>FieldThreeHeader</td> 
<td>FieldFourHeader</td> 
<td>FieldFiveHeader</td> 
</tr> 

<?php 
//Oracle DB Connection username and password etc here 

$s = OCIParse($connection. "select * from theTable"); 
OCIExecute($s, OCI_DEFAULT); 
while (OCIFetch($s)) { 
   print '<tr><td>' . ociresult($s, "FIELDONENAME") . 
'</td>'; 
   print '<td>' . ociresult($s, "FIELDTWONAME"). '</td>'; 
   print '<td>' . ociresult($s, "FIELDTHREENAME"). '</td>'; 
   print '<td>' . ociresult($s, "FIELDFOURNAME"). '<td>'; 
   print '<td>' . ociresult($s, "FIELDFIVENAME"). '</td></tr>'; 

} 

print '</table>'; 
?>

 

I cant download any softare in my environment due to many restrictions so I have to use what comes with the PHP standard load.  Please advise how I can get this to work.

Link to comment
Share on other sites

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.