Forum


Replies: 6   Views: 2828
Add progress bar
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by irishadar  · 18-02-2018 - 12:59

hi,

I am trying to add a progress bar to a "phpdocx" script.

but keep getting the error:

"Warning: Cannot modify header information - headers already sent by (output started at C:\phpdocx\dev\TetsugaPhotHeborg080218.php:332) in C:\phpdocx\classes\CreateDocx.inc on line 369"

Is it even possible?

can anyone shear with me what can I do?

 

I'm using this code in the PHP part :

echo " $vcurrent is $percent% of $vtotal <p/>";
ob_flush();
flush();
ob_end_clean() ;

and this code after the PHP code:

 <style>
  .outter{
          height:25px;
          width:500px;
          border:solid 1px #000;
  }
  .inner{
          height:25px;
          width:<?php echo $percent ?>%;
          border-right:solid 1px #000;
          background-color:lightblue;
  }
  </style>

  <div class="outter">
    <div class="inner"></div>
  </div>

 

Posted by admin  · 19-02-2018 - 08:05

Hello,

The following error:

Cannot modify header information - headers already sent by

is from PHP. PHP can't display output before using the header function; from http://php.net/manual/en/function.header.php:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

We recommend you to check your script to find where it's getting any output before the header.

Regards.

 

Posted by irishadar  · 19-02-2018 - 20:22

hi,

I have looked at my script but couldnt find what am i missing .

I have written a simple test case to demonstrate my problem .

so if I'm not using "createDocxAndDownload" all works well if i do i gets the warning

"Cannot modify header information - headers already sent by"

can someone point what is wrong with the script ?

thanks in advanced,

iris hadar

<?php
header( 'Content-type: text/html; charset=utf-8' );
require_once '../classes/CreateDocx.inc';
$docx = new CreateDocx();

echo 'Begin ...<br />';
for( $i = 0 ; $i < 10; $i++ )
{
    echo $i . '<br />';
    flush();
    ob_flush();
   sleep(1);
}
echo 'End ...<br />';

$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.';

$paragraphOptions = array(
    'bold' => true,
    'font' => 'Arial'
);

$docx->addText($text, $paragraphOptions);
$docx->createDocxAndDownload('../GrbCol/test');
?>

 

Posted by admin  · 20-02-2018 - 07:17

Hello,

You are using the echo method from PHP to print strings and then you are using the createDocxAndDownload method that uses the header function to download a document. PHP doesn't allow to do that (print strings before using the header function), please read the information about the header function on the PHP page.

Regards.

Posted by irishadar  · 20-02-2018 - 13:54

Thank you for the prompt answer.

So what is your suggestion for a "progress bar" displaying the creation status of the document ? 

 

tnaks

iris

Posted by admin  · 21-02-2018 - 07:19

Hello,

You can use XMLHTTPRequest using javascript or you can use PHP to generate a progress bar and other script to download it when it's finished or you can generate and use a hook system. There're many approaches to generate a custom progress bar, and the best and easiest solution depends on the project and the developer.

Regards.

Posted by irishadar  · 26-02-2018 - 07:09

To whom it may concern,

I have found this article and implanted it in my script it is working very well.

I've added some action to do when it reaches 100%.

http://w3shaman.com/article/php-ajax-progress-bar

iris