opening specific file chosen by user using a HTML form

Discussion in 'PHP' started by derek34, Nov 11, 2007.

  1. #1
    I need to figure out a way to open and display the contents of a text file. This would be very simple except I have to open a specific file chosen by the user.
    So here's what I've got so far:

    page1.php - The user enters a username and password and chooses a text file to open. They then press the send button and it goes to page2.php

    pag2.php - This is the one I'm having trouble with. The file that the user selected on page1 is then opened, converted to an array and displayed to the user in an HTML table.

    Firstly, I cannot figure out a way to open the specific file. I tried:

    $selectedfile = $_GET['course'].".txt";
    $arrayfile = file('./courses/$selectedfile');


    'course' being the name of the option menu on page1.
    This way did not work as it was looking for a file called '$selectedfile.txt'

    Secondly, after I get the file opened, how can I convert it into an HTML table?

    Thanks
    - Derek
     
    derek34, Nov 11, 2007 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    im not sure what you want to do,,
    is this like file upload or you want to view a page to next page??
     
    bartolay13, Nov 11, 2007 IP
  3. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    PHP won't parse inside single quotes for variables:

    echo '$x'; would output $x
    echo "$x"; would ouput whatever is in $x (although in this example quotes wouldn't be needed)

    $arrayfile = file("./courses/$selectedfile"); (or many other ways, plus you might want to add a bit of security on it)
     
    decepti0n, Nov 11, 2007 IP