473,569 Members | 2,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2311
In article <rInVe.14457$ct 5.12705@fed1rea d04>,
"Mike Brashars" <mi**@apayrolls ervice.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************ **********@g43g 2000cwa.googleg roups.com>,
"sunbum" <mb*******@gmai l.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\wwwro ot\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************ **********@g44g 2000cwa.googleg roups.com>,
"sunbum" <mb*******@gmai l.com> wrote:
Here is what I have now ... (without the line numbers)

1)<?
2) # Directory
3) $dir = "\inetpub\wwwro ot\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************ *********@g47g2 000cwa.googlegr oups.com>,
"sunbum" <mb*******@gmai l.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.tx t</option>
<option value='hello.tx t'>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

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

Similar topics

2
13760
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 the easiest way to take a huge project across onto it. Basically, I've hit a problem. I have no idea how the ifstream class handles directories....
2
11146
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 nature in the docs, aside from creating an array with 'scandir'...
1
4739
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 I have run into I am not sure how to fix, and really not sure what is causing it. Here's what is going on (test server - Windows 2003 Server): I...
1
6493
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 java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp...
0
4042
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 java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp...
4
5645
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) On each FileSystemItem Element, make two child nodes, one with the file name, one with the file size. ie. <filesystemitems> <filesystemitem>
0
2587
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 || DropDownStyle != ComboBoxStyle.DropDown) { base.OnSelectedIndexChanged(e); return; } OpenPickList(); }
65
5036
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 got errors of Failed to open file ./outdir/mytestout.txt. Below is the code: #include <stdio.h>
6
4242
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 this program has more then one class and also uses an interface. Right now I am working on ArrayBasedPD class. I am trying to write a code for the...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7614
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.