473,372 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Populate picklist from directory and return file name

Hi all,

I have been searching for a week and am unable to find and example to
"Populate picklist from directory and return file name".

I have a php script that reads a log file and plots a graph. Right now, the
log name is hard coded. The logs are archived each day in the form of say
ddmmyy.log and I would like to put a drop down list in the script that would
allow my script to run off the "log" picked or default to the current "hard
coded" name.

I thought this would be a really common thing but I guess not.

I would be open to a javascript or asp script as long as I could "feed"

the file name to my php script.

Can anyone point me to a script like this??

Thanks a million!


Sep 12 '05 #1
12 2289
In article <rInVe.14457$ct5.12705@fed1read04>,
"Mike Brashars" <mi**@apayrollservice.com> wrote:
Hi all,

I have been searching for a week and am unable to find and example to
"Populate picklist from directory and return file name".

I have a php script that reads a log file and plots a graph. Right now, the
log name is hard coded. The logs are archived each day in the form of say
ddmmyy.log and I would like to put a drop down list in the script that would
allow my script to run off the "log" picked or default to the current "hard
coded" name.

I thought this would be a really common thing but I guess not.

I would be open to a javascript or asp script as long as I could "feed"

the file name to my php script.

Can anyone point me to a script like this??

Thanks a million!


<?
# Directory
$dir = "/path/to/a/dir/";

print "<select name='file'>";
while (false !== ($file = readdir($dir))){
if (in_array($file, array(".", ".."))) continue;
print "<option value='$file'>$file</option>";
}
print "</select>";

?>

--
Sandman[.net]
Sep 13 '05 #2
Thanks Sandman!

It seems it doesn't quite like the print statements ......

Parse error: parse error, unexpected T_STRING in line 5, also in 7, it
doesn't like the "." in the array statement .... unexpected "."

Using php 4.3, IIS5

Thank you!

Sep 13 '05 #3
In article <11**********************@g43g2000cwa.googlegroups .com>,
"sunbum" <mb*******@gmail.com> wrote:
Thanks Sandman!

It seems it doesn't quite like the print statements ......

Parse error: parse error, unexpected T_STRING in line 5, also in 7, it
doesn't like the "." in the array statement .... unexpected "."

Using php 4.3, IIS5

Thank you!

I'm terribly sorry, one line was missing. This:

$dir = opendir($dir);

Should go before the while loop.

--
Sandman[.net]
Sep 13 '05 #4
Here is what I have now ... (without the line numbers)

1)<?
2) # Directory
3) $dir = "\inetpub\wwwroot\templogs\";
4)
5) print "<select name='file'>";
6) $dir = opendir($dir);
7) while (false !== ($file = readdir($dir))){
8) if (in_array($file, array(".", ".."))) continue;
9) print "<option value='$file'>$file</option>";
10) }
11) print "</select>";
12)
13)
14)?>

Still gives "Parse error: parse error, unexpected T_STRING in (script)
on line 5

:(

Mike

Sep 13 '05 #5
Found it!

oh dummy me, it was the "\" in my path needed to be $dir =
"/inetpub/wwwroot/templogs/";

now it works perfectly!!! Thank you!!

One last thing to bug you..... what holds the final selection of the
file? is it $file[select] ?

and what would signal that I am done selecting and want to do something
with the value?

Thanks so very much again!!

Mike

Sep 13 '05 #6
One last thing to bug you..... what holds the final selection of the
file? is it $file[select] ? and what would signal that I am done selecting and want to do something
with the value?


Make it into a form, with a submit button. See any HTML forms tutorial
for details.

---
Steve

Sep 13 '05 #7
In article <11**********************@g44g2000cwa.googlegroups .com>,
"sunbum" <mb*******@gmail.com> wrote:
Here is what I have now ... (without the line numbers)

1)<?
2) # Directory
3) $dir = "\inetpub\wwwroot\templogs\";
4)
5) print "<select name='file'>";
6) $dir = opendir($dir);
7) while (false !== ($file = readdir($dir))){
8) if (in_array($file, array(".", ".."))) continue;
9) print "<option value='$file'>$file</option>";
10) }
11) print "</select>";
12)
13)
14)?>

Still gives "Parse error: parse error, unexpected T_STRING in (script)
on line 5


Strange. It works like a charm for me. Maybe you got some strange invisible
character caught on that line?

--
Sandman[.net]
Sep 13 '05 #8
No, it worked great!

I think our messages just crossed.

It was the back slashes in my file path. Your code was perfect :)

Do you have any pointers on this....
One last thing to bug you..... what holds the final selection of the
file? is it $file[select] ?
and what would signal that I am done selecting and want to do something
with the value?


Thanks for all the patients and great help Sandman! you're the best

Mike

Sep 13 '05 #9
In article <11*********************@g47g2000cwa.googlegroups. com>,
"sunbum" <mb*******@gmail.com> wrote:
No, it worked great!

I think our messages just crossed.

It was the back slashes in my file path. Your code was perfect :)

Do you have any pointers on this....
One last thing to bug you..... what holds the final selection of the
file? is it $file[select] ?
and what would signal that I am done selecting and want to do something
with the value?


You are outputting a form, that will look something like this:

<select name='file'>
<option value='bonjour.txt'>bonjour.txt</option>
<option value='hello.txt'>hello.txt</option>
</select>

When you submit that form, it will be put in $_GET["file"] on the receiving PHP
script.
--
Sandman[.net]
Sep 14 '05 #10
Thanks Sandman,

Could you glance at this and see if I'm going in the right direction?

<?php
<html>
<head><title>Cooler Log Graph</title></head>
<body>
<form action="coolerlinec.php" method="post">;
# Directory
$dir = "/inetpub/wwwroot/templogs/";

print "<select name='file'>";
$dir = opendir($dir);
while (false !== ($file = readdir($dir))){
if (in_array($file, array(".", ".."))) continue;
print "<option value='$file'>$file</option>";
}
print "</select>";
<input type="submit" value="Submit">;
</form>

</body>
</html>
?>

Thanks again!

Anyone else is more than welcome to chime in too! The main function is
from "Sandman" and works great, I am now just trying to incorporate it
into a form. Obviously I am greener than grass ;)

Mike

Sep 14 '05 #11
Sorry for replying to my own post.

Here is the latest version and I think it's closer.

Can someone help me clean up the syntax?

Thanks!
------- Code begin (this is NOT in the script ------------------

<?php
if (isset($_POST['file']))
{
// process the data, see if it's valid.
// if it's valid and you're satisfied, do whatever you want with
the data
// if not, start outputting the form

$file = "/inetpub/wwwroot/templogs/"+$_POST['file'];
// Display the Graph
displaygraph();
}

else {
// display the form
displayform();
}

<?php
function displaygraph() {
echo "So far so good, this would draw graph with $file";

}
?>

<?php
function displayform() {
<form name="cooler" action="<?php $server['PHP_SELF']?>"
method=\"post\">";
$dir = "/inetpub/wwwroot/templogs/";

echo "<select name='file'>";
$dir = opendir($dir);
while (false !== ($file = readdir($dir))){
if (in_array($file, array(".", ".."))) continue;
print "<option value='$file'>$file</option>";
}
</select>;
<input type="submit" value="Submit">;
</form>

}
?>
?>

------- Code end (this is NOT in the script ------------------

Mike

Sep 14 '05 #12
In article <11**********************@g49g2000cwa.googlegroups .com>,
"sunbum" <mb*******@gmail.com> wrote:
Sorry for replying to my own post.

Here is the latest version and I think it's closer.

Can someone help me clean up the syntax?

Thanks!
------- Code begin (this is NOT in the script ------------------

<?php
if (isset($_POST['file']))
{
// process the data, see if it's valid.
// if it's valid and you're satisfied, do whatever you want with
the data
// if not, start outputting the form

$file = "/inetpub/wwwroot/templogs/"+$_POST['file'];
// Display the Graph
displaygraph();
}

else {
// display the form
displayform();
}

<?php
function displaygraph() {
echo "So far so good, this would draw graph with $file";

}
?>

<?php
function displayform() {
<form name="cooler" action="<?php $server['PHP_SELF']?>"
method=\"post\">";
$dir = "/inetpub/wwwroot/templogs/";

echo "<select name='file'>";
$dir = opendir($dir);
while (false !== ($file = readdir($dir))){
if (in_array($file, array(".", ".."))) continue;
print "<option value='$file'>$file</option>";
}
</select>;
<input type="submit" value="Submit">;
</form>

}
?>
?>

------- Code end (this is NOT in the script ------------------

Mike

The above is a good start. But you can't just start typing "<form name..."
inside a function block. You need to use

print "<form name='cooler' ....";
I always do my web app logic like this:
<?
while (1){
if ($_POST["file"]){
# Do fancy stufff
break;
}

# output form
$dir = "/inetpub/wwwroot/templogs/";
# ...

break;
}

--
Sandman[.net]
Sep 14 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Johnston | last post by:
Hi, I'm currently trying to create a wrapper that uses C functions but behaves like ifstream (from fstream.h) - this is because the platform I'm using (WinCE) doesn't support streams and this is...
2
by: 73blazer | last post by:
Hello, I'm writing some C++ code, and I need to be able to find the number of files in a given directory. Is it possible under AIX4.3.3 with C++ 3.6.4? I cannot seem to locate anything of this...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
4
by: | last post by:
Hi all, I want to create a method that does the following: 1) Programmatically instantiate a new XmlDataSource control 2) For each file in a named directory, make a "FileSystemItem" element 3)...
0
by: Andrus | last post by:
SWF ComboBox dropdown menu first item selection must open picklist. For this I use the following code: protected override void OnSelectedIndexChanged(System.EventArgs e) { if (SelectedIndex != 0...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
6
by: falconsx23 | last post by:
I am trying to write a code for a Phone Directory program. This program is suppose to allow the user to enter a name or directory and then program can either add, save or even delete an entry. Also...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.