Forum Moderators: coopster
<?
//define the path as relative
$path = "/hshome/etias/";
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<br/>";
//running the while loop
while ($file = readdir($dir_handle))
{
if($file!="." && $file!="..")
echo "<a href='$file'>$file</a><br/>";
}
//closing the directory
closedir($dir_handle);
?>
One question I have though...
Right now I have a couple forms in the html file that they fill out. The file is test.html. It then sends the info to post.php which parses it all and makes takes the questions and makes them into the name-namehere.html file. The namehere is the name of the person who took the test.
The admins can then login and see which files are there based on the names-whatever.html parsing and they can pick one and view the html file to see the answers and delete it.
Now that you know how it works. When the people take the test in the html file does it have to be in a separate file?
Can I take those forms that are in the html file and put them in a php file so it is all one or must it be an html that passes the arguments to the php?
I hope that made sense
if($file!="." && $file!=".." &&!preg_match("/^name-/",$file)){
The real code is
if($file!="." && $file!=".." &&preg_match("/^name-/",$file)){
You had it checking to make sure preg_match DID NOT match by adding the!.
Thanks for the code, it works wonders
while ($file = readdir($dir_handle))
{
if($file!="." && $file!=".." &&preg_match("/^name-/",$file)){
echo "<a href='$file'>$file</a><br/>";
}
}
How would I make it that for the echo it would do the full a href like it is but for the display part of the link it would only be what is AFTER name-?
So if the file was name-bob.html it would make that the link and just display bob
>> When the people take the test in the html file does it have to be in a separate file?
no it could be appended to one master file. You could use a comma delimited format or maybe pipe delimited depending on what kind of input there is. This would be a flat file database.
I have a few questions
what happens when 2 people with the same name take the test, does it overwrite the file?
why not, as you asked, use a single file, or even better a database?
why the strange naming convention for the files, why not just their full name .html?
As for using a database or a single file...I just started PHP yesterday by teaching myself and I thought that if you have a submit form it had to send it to an external file.
Such as:
<form method="post" action="post.php">
What is your character name?<BR>
<input type="text" size="20" maxlength="40" name="name">
....
....
....
<textarea rows="5" cols="40" wrap="physical" name="questionten">
</textarea><BR><BR>
<input type="submit" value="Submit Answers">
</form>
I thought I then had to have it go to post.php. If this is all in a php file I am not sure how that would work. Can it post to itself?
write them to file
write them to a database
send them in email
the only restriction is what you can code ;)
>> Also, I don't see us ever becoming HUGE
no one ever does but who knows :)
alright, given the low traffic then maybe using a single file might be better. A single csv file would work.
1. when someone takes the test it just appends a new row of data to the file
2. when an admin wants to view it, a script loops through and grabs the rows from the file, when they are done the row can be deleted
as far as reading from CSV maybe try this thread from our Library [webmasterworld.com]
[webmasterworld.com...]