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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:42:00+00:00 2026-06-07T20:42:00+00:00

First off, I am totally new to PHP, but so far i love the

  • 0

First off, I am totally new to PHP, but so far i love the possibilities i have seen with it.

Ok, heres my problem. I have a script that will automatically scan a folder and show me the file names of that folder in a drop-down menu.

<?php
$dirname = "logs";
$dir = opendir($dirname);
echo '<select name="file2">';
echo '<option value="">Logfiles</option>';
while(false != ($file = readdir($dir)))
        {
            if(($file != ".") and ($file != ".."))
                {
        echo "<option value=".$file.">$file</option>";
                }
        }
                echo '</select>';
?>

So far so good, that part works just fine.

I then have a piece of code that would show me the contents of a chosen file.

<?php
$content = file("filenamehere");
$data = implode("<br>",$content);
echo $data;
?>

This part on its own also works fine.

I now want to combine these 2 scripts. This is where i get totally lost. I have tried all various combinations of which variable to put as a “filenamehere”, but I only get as far as having my choice from the drop-down echoing the chosen filename in the drop-down button. I have not been able to actually get the 2nd part of the code to display the file contents of the file I have chosen. I tried things like (“$file”) for the $content variable but nothing happens.

Of course any other single script solution would also be great. I just need to be able to scan a folder, have its files listed in a drop-down, and once i choose a file i want it to be displayed on the page.

Any help would be deeply appreciated since im a total beginner in PHP.

Cheers.

  • 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-07T20:42:02+00:00Added an answer on June 7, 2026 at 8:42 pm

    Am assuming you are doing everything in a single page. I have wrapped a form tag around the select dropdown and added a submit button

    echo '<form name="displayfile" action="" method="POST">';
    echo '<select name="file2">';
    echo '<option value="">Logfiles</option>';
    while(false != ($file = readdir($dir)))
            {
                if(($file != ".") and ($file != ".."))
                    {
            echo "<option value=".$file.">$file</option>";
                    }
            }
                    echo '</select>';
    echo '<input type="submit" value="display file" />';
    echo '</form>';
    

    The second part

    <?php
        //file2 is the name of the dropdown
        $selectedfile = @$_POST['file2'];
        $content = file($selectedfile);
        $data = implode("<br>",$content);
        echo $data;
    
    ?>
    

    Hope this helps

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

Sidebar

Related Questions

First off, let me start by saying that I am totally new to working
first off I'm a noob to PHP but here is my problem. I am
First off, I am a totally new developer with regards to Node.js. I have
First off, I would like to make clear, that I am SUPER NEW TO
First off I have an app that provides the user information about the amount
First off, I have never used VBA (or VB for that matter), so keep
First off, I've never used GWT before. I have good experience in HTML/CSS/JS/JSP. I'm
First off, I did look on google and stackoverflow, but nothing seem to really
First off, a big thanks to the people behind the new boost::geometry library! This
First off, I'm pretty new so I hope I hadn't missed anything too trivial.

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.