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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:39:57+00:00 2026-06-07T16:39:57+00:00

I apologize in advance for the confusing question wording, but I couldn’t figure out

  • 0

I apologize in advance for the confusing question wording, but I couldn’t figure out how to put this.

I essentially have a string in a database that I intend to make available for user download. How would I go about doing this?

I was attempting to use ajax, but I wasn’t sure how to go about it.

The following jquery code is executed when the download link is pressed

$.ajax({

    url: 'index.php/script/downloadFile',
    type: 'post',
    data: {name: $(this).text()}

});

The relevant PHP code looks like:

public function downloadScript(){

    $name = $_POST['name'];

    $filename = $name . ".txt";
    $string = //String that comes from database using name to create query
    $filename = $name . ".txt";

    header('Content-type: text/plain');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header("Content-Length: " . strlen($string));
    header("Connection: close");

    echo $string;
}

Essentially, I want the string to be there for a user to download as a text file. I didn’t know if AJAX was the right way to do this or if there was a better way to do the same task. (I was assuming the better way would be to incorporate a hidden iframe somehow)

For a little more information, I have a list of elements:

  • John
  • Jeff
  • Joe
  • Jack
  • When one is clicked, I want to send the text of that element’s name to the php file to form the query.

    That’s why I don’t have a simple href setup to start the file download.

    EDIT:

    While I’m at it, is there anyway for me to get more than one of these files, say there are multiple strings that are returned from the database, save them as separate text files, zip them up, and send them to the user? Or, would that require saving to the server?

    Any help is appreciated!

    • 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-07T16:40:01+00:00Added an answer on June 7, 2026 at 4:40 pm

      You could just make it a link

      <ul>
          <li class="click_link">John</li>
          <li class="click_link">Bob</li>
      </ul>
      
      <script>
      $('li').click(function(e) {
          window.location.href = 'getfile.php?name=' + $(this).text();
      });
      </script>
      

      Then change your $_POST to a $_GET.

      This will download the file as long as your headers are set correctly.

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

    Sidebar

    Related Questions

    I apologize in advance for the rambling nature of this question, but I have
    I apologize in advance for this somewhat ignorant question, but I have researched this
    This is a very noobish question, so I apologize in advance! I have two
    I apologize in advance because this is somehow a silly question, but I just
    I apologize in advance for asking this question, I know similar questions have already
    I apologize in advance for the wording of the question... I have a table
    I apologize in advance for this newb question, but I've been struggling with the
    I apologize in advance for the stupidity of this question, but I am confused
    I apologize in advance if i'm not wording this properly. I have a textbox
    I apologize in advance if this question is deemed too trivial, but I did

    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.