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
https://forums.phpfreaks.com/topic/55792-generate-word-document-from-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.