drupal 6 can we write a php file in drupal which changes the headers
i have written a small code which creates a word document but i got the following errors
require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); global $user;
$fp = fopen("test.doc", 'w+');
$str = "<B>This is the text for the wor开发者_如何学God file created through php programming</B><br>test to create a doc file from php";
ob_start();
include('index.php');
$result = ob_get_clean();
fwrite($fp, $result);
echo "executed";
header("Content-Disposition: attachment; filename=test.doc"); header("Content-Type: application/force-download"); header("Content-Length: " . filesize("test.doc")); header("Connection: close");
fclose($fp);
?> warning: Cannot modify header information - headers already comnt by (output started at /var/www/www.example.com/htdocs/test_createdoc.php:6) in /var/www/www.example.com/htdocs/test_createdoc.php on line 19. warning: Cannot modify header information - headers already comnt by (output started at /var/www/www.example.com/htdocs/test_createdoc.php:6) in /var/www/www.example.com/htdocs/test_createdoc.php on line 20. warning: Cannot modify header information - headers already comnt by (output started at /var/www/www.example.com/htdocs/test_createdoc.php:6) in /var/www/www.example.com/htdocs/test_createdoc.php on line 21. warning: Cannot modify header information - headers already comnt by (output started at /var/www/www.example.com/htdocs/test_createdoc.php:6) in /var/www/www.example.com/htdocs/test_createdoc.php on line 22
i have even remove the white spaces between php tags
It looks like echo "executed";
sends output before the headers. PHP then stops the headers from sending, because HTTP requires headers to come before output. If removing that doesn't fix it, try commenting out include('index.php');
to test if the output is coming from there.
精彩评论