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 7671001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:56:59+00:00 2026-05-31T15:56:59+00:00

I have an HTML select form that populates my list with elements found in

  • 0

I have an HTML select form that populates my list with elements found in my database like so:

    <form action="" method="POST">
    <select name="item_select">
    <?php 
    $query = "SELECT * FROM files_table";
    $result = mysql_query($query);
    while ($row = mysql_fetch_object($result)) { 
    ?>
        <option value=<?php echo $row->id; ?> > <?php echo $row->file_name;  ></option>
        <?php }// end while?>
    </select>
    <br /><br />
    <input name="show_png" type="submit" value="Show" />
    <input name="delete" type="submit" value="Delete" />
    <input name="download_text" type="submit" value="Download .txt File" />
    <input name="download_image" type="submit" value="Download .png File" />
</form> 

I have functionality for the “Show” and “Delete” buttons of the form to show and delete the content stored in the database. However, I’m having trouble figuring out a way to have the user download a file. Right now, my basic strategy is this:

if (isset($_POST['download_text'])) {
  // Code to create .txt file from content (omitted).
  // File name of content stored in $file_name variable.

  // Download file.
  header('Content-type: text/plain');
  header('Content-Disposition: attachment; filename="sample.txt"');
  readfile($file_name);
}

This sort of works. What I mean by that is I download a file that contains the contents, but what’s wrong is I also see the html form in plain text following this content. Is there someway to ensure this does not show up?

  • 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-05-31T15:57:00+00:00Added an answer on May 31, 2026 at 3:57 pm

    die() after the readfile.

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

Sidebar

Related Questions

I have a html form which have a select list box from which you
I have this HTML dropdown: <form> <input type=text id=realtxt onkeyup=searchSel()> <select id=select name=basic-combo size=1>
I have a form in a .html files where input/select box looks like this
I have a button on a form that is dynamically spawning a select list,
Let's say I have an html form. Each input/select/textarea will have a corresponding <label>
I have the following multi-select box in a HTML form, where user can select
I have a html element (like select box input field) in a table. Now
I have this html... <select id=View name=View> <option value=1>With issue covers</option> <option value=0>No issue
I have a simple form that I would like to validate on form submission.
I have a select tag that is populated with a list of files each

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.