php header function call fails due to class.wp-style.php file
-
As part of what I am doing for a children’s charity in India I am setting up a small document management system. From my php plugin I can create folders and upload documents OK. I am struggling to download documents. To illustrate my problem I have set up a small test page which tries to download a file.
You can access the page at: https://www.testdb.org/?page_id=6992
As you will see when I run the page I get a warning for each call of header().
The warning is:
Warning: Cannot modify header information – headers already sent by (output started at /home/healit/testdb.org/wp-includes/class.wp-styles.php:225) in /home/healit/testdb.org/wp-content/plugins/healdb/include/health_camp.php on line 6The problem I have is since it is saying output has already been generated by a system file (class.wp-styles.php:225) I can’t use header calls.
What is the solution to this?
The test code is just trying to download a file from the server. For test purposes I have hard wired the file path into the code.
The test code is listed below:
Many Thanks for any help you can give,
Colin Charlton<?php function health_camp() { $file_name = "documents/uk/board_meetings/2019-11-29/Technical Report"; header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file_name).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file_name)); readfile($file_name); }The page I need help with: [log in to see the link]
The topic ‘php header function call fails due to class.wp-style.php file’ is closed to new replies.