Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8970745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:46:57+00:00 2026-06-15T17:46:57+00:00

I have a file, index2.php that has been written to by a form. The

  • 0

I have a file, index2.php that has been written to by a form.

The whole content of this file, I have stored within a variable $final_code using an output buffer.

I now wish to add a “Download” button to the end of the page, that brings up a Save As dialog, allowing the user to save this file’s source code (i.e. the variable) as a .txt – But I’m stumped.

index2.php:

<?php

// Start buffering the output
ob_start();

?>

<!-- INDEX2.PHP HTML ELEMENTS HERE -->

<?php
// Store the contents of the buffer
$final_code = ob_get_contents();

// Print the contents of the buffer
ob_end_flush();
?>

<form action="savefile.php" method="post">

Happy? Save this to file: <input type="submit" name="savefile" value="Save" />

</form>

I’m not sure if this needs to be worked in to this file or savefile.php, so the latter is currently blank.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:46:59+00:00Added an answer on June 15, 2026 at 5:46 pm

    i think you cannot force a save as file dialog in browser.

    for forceing the download of a txt file i do the following:

    header('Pragma: anytextexeptno-cache', true);
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private", false);
    header("Content-Type: text/plain");
    header("Content-Disposition: attachment; filename=\"example.txt\"");
    echo $output;
    

    hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a index.php file that will include several external files: content/templates/id1/template.php content/templates/id2/template.php content/templates/id3/template.php
have a form that a name has been entered and need to add it
I have a PHP script (index.php) that includes an index.html file in a sub-directory
I have a file system structure with symlinks, something like this: folder123 index.php config.php
I have an index.php file which has 2 included files require(stats.php); require(stats_encry.php); stats.php which
Iam making an app which has one index.php file. I also have these other
I've got a very old php application (1999) that has been worked on during
I have a PHP program that has the user copying a URI into a
So I have a dashboard controller that points to the corresponding view. This file
If I have an index.php file that includes inc/footer.php I would write: include 'inc/footer.php';

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.