 |
 |
Help with simple PHP script
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
I currently have a PHP script set up to deal with users' contact information. Users enter their info into a form and my PHP script formats the contact info into a neat HTML table. That table gets mailed off to blogger and blogger handles appending the post to a web page. It works well except that it can't be sorted. I knew of that limitation before I started this system so I also made the PHP script write the table out to a file, a new file for each user, the name of the file is the user's full name (last, first) and I have those files saved to one of 3 directories (depending on a category that the user selects in the form).
That works fine but now I need to create a PHP script to take an entire folder of these files that contain tables and display to the browser one long html file of all of the tables, in alphabetical order.
I don't really know PHP (I've been copying and modifying code from various places to get this stuff done so far). So I don't really know where to start for this one. Can anyone help me out? Thanks.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
one way to do this:
1) make an array
2) find all files in the dir. and start a for loop (probably use foreach)
3) open each file and explode by table
4) append to the array
5) sort array
6) print array
just seems logical, I am not sure the exact way for #2 but i can help with the others.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
OK thanks. I know I can use readfile() to read in a file into a buffer and I can then echo that buffer out. I guess my question is how do I go through every file in a directory, in order?
Your idea would be to make the array and then sort it, but since I want everything sorted by filename, shouldn't I just be able to read them in the right order?
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
Code:
while ($fileName = $dir->read())
{
if ($fileName != "." && $fileName != "..")
{
if (is_file($fileName))
{
echo "$fileName \n";
take a look at php.net for more nice examples.
also just a personal preferance, i like fopen() more then readfile()
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
Parse error: parse error, unexpected $ in /var/www/html/members/summer/contacts03/test.php on line 9
That's what I get when I run that script as is. What do I need to fix? (it's only 8 lines long so I don't understand the error.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
ok that was dumb of me. now that i've closed all three braces I get this error:
Fatal error: Call to a member function on a non-object in /var/www/html/members/summer/contacts03/test.php on line 2
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by waffffffle:
ok that was dumb of me. now that i've closed all three braces I get this error:
Fatal error: Call to a member function on a non-object in /var/www/html/members/summer/contacts03/test.php on line 2
He's used an example which calls a class which you've probably not included with your code:
$dir->read();
Perhaps do a search on PHP.net for that line of code and you'll find the missing bits...
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Aug 2002
Status:
Offline
|
|
$d = dir("/etc");
where /etc is your starting directory
and make sure to finish with
$d->close();
($d is a handle of class dir if that helps)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
thanks but I think I got it on my own. I found this script that lists the contents of a directory and I modified it to print out the directory:
<?php
function getDirList ($dirName) {
$d = dir($dirName);
while($entry = $d->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($dirName."/".$entry)) {
getDirList($dirName."/".$entry);
} else {
$string = "html";
if(strstr($entry,$string)) {
//echo "$entry<br>\n";
$filbuffer = readfile($entry);
echo "$filebuffer<br>\n";
}
}
}
}
$d->close();
}
getDirList(".");
?>
It works nicely. Thanks to everyone for the help.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: New York
Status:
Offline
|
|
this seemed to be working fine for a while but now all of the new items that are added are getting put at the bottom of the list. Why would this script read the files out of order? At first it looked like a permissions thing (the files were being created by a different owner and with different permissions because I recently moved the entire site to a different server. However I went in and manually fixed the permissions and I still get the same problem. I don't get it.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|