What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP File Indexer

PHP File Indexer
Author: Message:
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. PHP File Indexer
How could I take this code and output the result to a txt file on the server?

code:
<?php
$maindir = "." ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php") ;
while($fn = readdir($mydir)) { if ($fn == $exclude[0] || $fn == $exclude[1]) continue;
echo "<br><a href='$fn'>$fn</a>"; } closedir($mydir);
?>


What it does is it lists all the files in that folder that the indexer.php is in.
So how would I take that list and put it in a txt file?

If any one knows of a simpler or better way of outputting all the file names and the links to them in a txt file on the server please feel free to post it.

This post was edited on 03-01-2005 at 12:43 AM by DJeX.
[Image: top.gif]
03-01-2005 12:42 AM
Profile PM Web Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
38 / Male / Flag
Joined: Aug 2004
Status: Away
RE: PHP File Indexer
You can use the output buffer functions. :o

Just before the while(), put ob_start() and in the end of the loop, put $tofile = ob_get_contents();

And that goes to the file. You know, fopen() and fwrite()?

:P I'm feeling lazy, sorry.

code:
ob_start();
// while loop
$text = ob_get_contents();
$op = fopen($file,'w'); // or 'a' if you want to append it
fwrite($op, $text);
fclose($op);


I find that easier than putting variables all over the place.

This post was edited on 03-01-2005 at 12:49 AM by L. Coyote.

Hack, hack, hack!
Finally became a Systems Analyst! :spam:

03-01-2005 12:45 AM
Profile PM Find Quote Report
TheBlasphemer
Senior Member
****

Avatar

Posts: 714
Reputation: 47
36 / – / –
Joined: Mar 2004
RE: PHP File Indexer
how about putting fopen at the start,
fclose at the end, and replace the echo by fwrite?
[Image: theblasp.png]
03-01-2005 12:55 AM
Profile PM Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: PHP File Indexer
Ive tryed this code

code:
<?php
$maindir = "." ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php") ;
while($fn = readdir($mydir)) { if ($fn == $exclude[0] || $fn == $exclude[1]) continue;
$file = fopen("file.txt","w");
fwrite($file,"<br><a href='$fn'>$fn</a>"); } closedir($mydir);
fclose($file);
?>


But alls it wrote in the txt was:

code:
<br><a href='indexer.php'>indexer.php</a>
[Image: top.gif]
03-01-2005 01:04 AM
Profile PM Web Find Quote Report
TheBlasphemer
Senior Member
****

Avatar

Posts: 714
Reputation: 47
36 / – / –
Joined: Mar 2004
RE: PHP File Indexer
quote:
Originally posted by DJeX
Ive tryed this code

code:
<?php
$maindir = "." ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php") ;
while($fn = readdir($mydir)) { if ($fn == $exclude[0] || $fn == $exclude[1]) continue;
$file = fopen("file.txt","w");
fwrite($file,"<br><a href='$fn'>$fn</a>"); } closedir($mydir);
fclose($file);
?>


But alls it wrote in the txt was:

code:
<br><a href='indexer.php'>indexer.php</a>



put the fopen BEFORE the while!
[Image: theblasp.png]
03-01-2005 01:07 AM
Profile PM Find Quote Report
DJeX
Veteran Member
*****

Avatar


Posts: 1138
Reputation: 11
– / Male / –
Joined: Jul 2003
O.P. RE: PHP File Indexer
lol ok thanks it worked
[Image: top.gif]
03-01-2005 01:08 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On