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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:08:15+00:00 2026-06-01T20:08:15+00:00

I have my code to display information from a text file already: $myFile =

  • 0

I have my code to display information from a text file already:

$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;

But I can’t figure out a way to make the above not show until a button is clicked. I tried making it a function but I suppose I wasn’t doing it right. I also tried using a submit button that set a cookie and once the cookie was set it displayed the above, but it didn’t work either. Are there any other methods to do this? It seems pretty easy, I just can’t quite get it to work properly.

Edit: I want to have this all done on one page, no redirecting to another page.

  • 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-01T20:08:16+00:00Added an answer on June 1, 2026 at 8:08 pm

    It seems that you dont need to necessarily read the file on the triggered action of clicking a button. If you are already reading the file, load it into a hidden HTML element, like a <div>, then use Javascript to show that on the click of the button.

    PHP:

     $myFile = "file.txt";
        $fh = fopen($myFile, 'r');
        $theData = fread($fh, filesize($myFile));
        fclose($fh);
        echo '<div id="hidden_content" style="display:none">'.$theData.'</div>';
    

    HTML Link:

    <a href="#" onclick="show_content()">Show it!</a>

    Javascript:

    function show_content(){
        document.getElementByID('hidden_content').style.display = 'block';
    }
    

    Although if you are trying to read data dynamically based on what you click, that has to be done via AJAX as mentioned before.

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

Sidebar

Related Questions

I already have Java code to display and process data from a database. I
I have this code to display the data retrieved from DB in accounts_view.php :
I have tried using the below code modified from http://www.html5rocks.com/tutorials/file/dndfiles/ to read in a
I have as input text a big html file from where I have to
I am trying to create a GUI to display information read from a file.
I have a datagrid to display some information from a SQL table, and then
From my previous question I have solved how to display information from MS Access
I have a plist file that holds information I need to display in an
I am trying to display statistics from a simple text file using arrays in
I have this code: def display(self): print self.doc.toprettyxml(indent= ) strigName ='/Users/my_user/Desktop/python/' + str(datetime.datetime.now()) +

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.