Results 1 to 9 of 9

Thread: Script to display contents of a text file

  1. #1
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Script to display contents of a text file

    I have a CGI script that increments a "counter" and writes the contents of counter to "counter.txt". This counter.txt file consists of one line and the data is a number. I want to display this number on a web page using a script. Seems simple, but I haven't come accross a script in my search.

    Thanks in advance for any help.
    CL

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Using PHP, this is quite easy.

    Include the following line anywhere in your page, and it will be displayed there:
    <?php echo file_get_contents('path/to/mytextfile.txt'); ?>

    You must use PHP for this to work, meaning:
    1) page must end with .php (instead of .htm, and this won't hurt anything... works fine with html)
    2) you need PHP installed/running on your server

    Good luck.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you djr33.

    I will look into PHP. I don't know if my ISP has the server components for PHP installed.

    I was hoping for a javascript, as I am a little more famaliar with javascripts.

    -CL

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It is much better to use PHP for this and allows more control. (ASP, SSI [serverside includes], and other methods would work as well. PHP is just one serverside language.)

    If you must go with Javascript, I believe you would need to use Ajax, which is much more complex and really shouldn't be needed for this. It's possible, though.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by djr33 View Post
    If you must go with Javascript, I believe you would need to use Ajax
    Either way, you would need to use some sort of server side invocation for the AJAX script to work properly (unless you used Active X Controls - which is only available in IE).

    Hope this helps.

    EDIT: Misread the question. Thought you were trying to edit/write to a text file.
    Last edited by thetestingsite; 04-11-2007 at 03:54 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ajax can call a .php page; can it not call a .txt 'page'?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Ajax can call a .txt document.

    And I've never seen a web host that'll allow CGI but not PHP.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    But it might have ASP, just CGI, etc. available/installed and not PHP, with that either needing to be installed, or just not available with that webhosting company.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by tech_support View Post
    I've never seen a web host that'll allow CGI but not PHP.
    I have seen several that only allow perl scripts, and nothing more. I have also seen some that only have support for PHP without database support (if they needed it). It really all depends on the webhosting company (and/or the servers in which the user hosts the site on).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •