PHP web page generates a Word Document

Discussion in 'PHP' started by kensington, Jun 15, 2007.

  1. #1
    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:
    
    <?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>'; 
    ?>
    
    Code (markup):
    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.
     
    kensington, Jun 15, 2007 IP
  2. dzysyak

    dzysyak Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried to look what you are getting? I mean the sources ofthefile returned by the script, the one that opens blank page in word document? Is it really empty? try for example to change the following line:

    
     header( "Content-Type: application/msword" ); 
    
    PHP:
     
    dzysyak, Jun 16, 2007 IP