Jump to content

Can I create a form to Browse/Select a file Local to the Web Server


SecureMind

Recommended Posts

Here's the problem,

 

1. I have an application that dumps a specific type of log file to a drive on the server it runs on.

2. The file is named with a name based on a number of factors such as IP addresses and so on.

3. I'm running a number of scripts and pages based on parsing that local file.

 

I would like to have a form that will allow me to browse and select one of these local to the webserver files. (not to be confused with the ability to browse files local to the end user)

 

Any suggestions.

 

Thanks,

 

Josh

You should certainly be able to iterate through the files and create a list that could be output in some way allowing the user to choose (anchor links, dropdown box etc. But if your asking if theres a handy 'Open File' type dialog then I fear the answer is no.

Ok so I tried this to start with. This looks at all the files in the directory and creats a listing

 

<?php
/*
This is for creating an uploadeded file list
*/
$source  = opendir("upload/");
$HTML = "";
$alt = "stripped file";
$count = 0;
if($source){
        while(($file = readdir($source)) !== false){
                if(!is_dir($file)){
                        $HTML = $HTML ."<a href=\"upload/$file\" >$file</a>\n";
                        $count++;
                }
                if($count == {
                        $HTML = $HTML . "<br />";
                        $count = 0;
                }
        }
}
else{
        echo "could not open directory";
}
echo $HTML;
?>

 

Then I call it within a web page with this:

 

<?php
include('sample.php');
?>

 

The next question is, lets say I do indeed want to have this as a drop down selection menu... what my next step?

If you wish to use a dropdown selection then rather than append an anchor link you would be using

 

$HTML = '<selection name="file">';

// then in the loop
$HTML .= '<option>' . $file . '</option>';

// then after the loop

$HTML = '</selection>';

You'd probably also add form tags at the top and bottom and a Submit button, it all depends on the overall layout of your code etc and what you need.

ok so I think I've got this, I:

 

<?php
/*
This is for creating an uploadeded file list
*/
$source  = opendir("upload/");
$HTML = "";
$alt = "stripped file";
$count = 0;

$HTML = '<selection name="file">';

if($source){
        while(($file = readdir($source)) !== false){
                if(!is_dir($file)){
                        $HTML .= '<option>' . $file . '</option>';
                        $count++;
                }
                if($count == {
                        $HTML = $HTML . "<br />";
                        $HTML = '</selection>';
                        $count = 0;
                }
        }
}

else{
        echo "could not open directory";
}

echo $HTML;
?>

 

So now I still get just a text file output with:

 

<?php
include('sample.php');
?>

 

now I assume I need to take that and somehow move the $HTML into a dropdown box?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.