Build Your Own Database Driven Web Site Using PHP & MySQL

Hello, i am just getting start with MySQl and PHP, i flowed the course it was so helpful.
Now i am trying to do the same thing here but with “Download” button in order to download the joke in .txt file . can any one help me please.


    header('Content-type: text/plain');
    header('Content-Disposition: attachment; filename="download.txt"');
    //Your Code to Put File Contents Here
1 Like

Thanks for your answer ; But would you explain more because i don’t understand in which part i should add your code .

we don’t know either, as you did not post any code.

I have a feeling that the header() function may be something that catches out every developer at some point early on. The docs have some helpful information.

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. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

/* This will give an error. Note the output
* above, which is before the header() call */

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.