Scripting Help (PHP)

Messages
341
Reaction score
0
Points
0
Thanks everyone that helped me with that. Does anyone know of a script that will include the first line of text in a file? Here is a example.

file.txt contains:

Line 1: Test
Line 2: Test2

Then index.php Shows:
Test
 
Last edited:

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Directly from the PHP Manual.

opendir(), readdir(), closedir()

PHP:
<?php
$dir = "/home/username/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    }
}

?>
 

deadimp

New Member
Messages
249
Reaction score
0
Points
0
Also googling something like "php directory scan" or "indexing" ought to turn something up along those lines.
If all else fails, "php file browser".
 
Messages
341
Reaction score
0
Points
0
Thanks everyone that helped me with that. Does anyone know of a script that will include the first line of text in a file? Here is a example.

file.txt contains:

Line 1: Test
Line 2: Test2

Then index.php Shows:
Test
 

Russ

<b>Retired *****</b>
Messages
3,168
Reaction score
2
Points
38
Actually going to move this to scripting help..
 

medphoenix

New Member
Messages
354
Reaction score
0
Points
0
This quoted script will be the php code for opening the first line of your text file.
<?php
$fp = fopen("file.txt","r");
if ($fp)
{
$line = fgets($fp, 100);
echo "$line<br><br>";
fclose($fp);
}
?>

both (index.php,file.txt) should be in same folder.
 
Top