[Support request] PHP error in hook element

Home Forums Support [Support request] PHP error in hook element

Home Forums Support PHP error in hook element

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1589516
    Sean

    I’m trying to create a button that downloads a text file that is generated from a php script.

    So far I have:

    <?php //Generate text file on the fly
     
    header("Content-type: text/plain");
    header("Content-Disposition: attachment; filename=savethis.txt");
     
    // do your Db stuff here to get the content into $content
    print "This is some text...";
    print $content;
    ?> 
    

    If I use a hook to show this after the content on a page I get the following error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/onecards/public_html/wp-includes/class.wp-styles.php:290) in /home/onecards/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(196) : eval()’d code on line 3

    Warning: Cannot modify header information – headers already sent by (output started at /home/onecards/public_html/wp-includes/class.wp-styles.php:290) in /home/onecards/public_html/wp-content/plugins/gp-premium/elements/class-hooks.php(196) : eval()’d code on line 4

    If I put the code into a .php file and call that with a href link it works.

    Thanks!

    #1589753
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Hooks aren’t meant to be used with PHP like this – you need to use a custom .php file instead.

    Hooks are built for displaying elements on the front-end of your website. If you need to output content from a file, you can look into a function like file_get_contents().

    Let us know if you have any other questions 🙂

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.