How can I make a save file as button, something similar to

<input type="file" name="myfile">

except I don't want it to be input I want it to be output. And also how can I write things to a text file and then save the text file to whatever location is given?

    read up on the [man]header[/man] fucntion. there are examples on the manual page of what you are trying to do.

      I'm not sure I understand how to use that. From another php file I would then need to put a link to this file? Is there a way to get a save file button, that when clicks pops up the save file dialogue?

      Also for some reason the default name is not the suggested name of the file (downloaded.pdf) but rather the name of the file that I saved it as (test.php or something like that).

        a simple example:

        <?php
        if (isset($_GET['download']))
        {
        	$text = 'this is some text that i want to save to a file';
        	header('Content-type: text/plain');
        	header('Content-Disposition: attachment; filename="file.txt"');
        	echo $text;
        	exit();
        }
        
        echo '<a href="' . $_SERVER['PHP_SELF'] . '?download=true">download file</a>';
        ?>
        

          How can I make a form that doesn't have blank space above and below, is this possible?

            Originally posted by hwttdz
            How can I make a form that doesn't have blank space above and below, is this possible?

            i don't understand what you mean. what does this have to do with the subject of this thread?

              Well I was trying to put the text file generating segment of script in the same php file as the rest of the functionality but that seemed to be impossible so I needed to move it to a different file. Then I did essentially what was suggested earlier and had an a href="php_file_that_makes_text" but I couldn't get that on a button, so I tried using a submit button, and a plain button neither of which worked.
              i.e. <a href="stuff"><input type="button" value="download"></a>
              but that didn't work. So I made a new form which has as it's action the file that makes the text file but now I have some funny looking formatting. It looks like there's a line break between the end of one form and the start of the next.

                I think means this.
                <form ..> tag can sometimes make an empty line before it display itself.

                To overcome this, you can put form inside a table:
                table class='tform" tr
                td form start
                form end /td
                /tr /table

                and in CSS stylesheet:
                TABLE.tform {
                width: ..
                height: ..
                }

                I know most usual is to put a table inside form tags
                but I do this the other way ->my way

                🙂 halojoy sings: "I did it My Way"

                  Write a Reply...