Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    20
    Thanks
    5
    Thanked 0 Times in 0 Posts

    put number of data files on server into javascript variable

    Hello,

    Hopefully this is a pretty basic questions, but my level of php knowledge is even more basic at this point...

    On my website, a user enters at Page 1, completes a short game on Page 2, and is fare-welled on Page 3. Also on Page 3, a unique text file is created with data and stored on the server in a folder called "data".

    Thus, the number of text files in the folder "data" is represents a count of how many users have made it to Page 3.

    I would like to know how many users have made it to Page 3 on Page 1. Thus, I was thinking that there might be some php code I could use on Page 1 to search in the server side folder called "data", count how many text files there are, and then create a javascript variable with that number.

    Any help would be very appreciated.

    Cheers,
    Adrian

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,081
    Thanks
    23
    Thanked 592 Times in 591 Posts
    Off the top of my head I don't know how to count files in a folder. I suppose there is a way and I'm sure someone will enlighten us, but in the mean time....

    Things would be a lot simpler if you used a database to keep your information, the number of files could increase into the thousands. My suggestion is to have a file that contains a number. That number is the number of files in your folder. When you reach page three, open that file and set a variable to that number and add 1 to it. Then when you store your file on the user over write the number file. It will always have the latest and truest count of people that have made it to page three and can be accessed from page one.

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $directory "../datafiles/";
    if (
    glob($directory "*.txt") != false)
    {
     
    $filecount count(glob($directory "*.txt"));
     echo 
    $filecount;
    }
    else
    {
     echo 
    0;



  •  

    Posting Permissions

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