Page 1 of 3
Letters
Posted: Mon Aug 19, 2002 9:27 pm
by Silver_Eclipse
how would i make a script that prints the whole file? i have tried the fread and fgets but when i try to print it, it only prints out one letter.
Posted: Mon Aug 19, 2002 9:34 pm
by volka
Code: Select all
$filename="test.txt";
$fd = fopen($filename, "rb");
while($line = fgets($fd, 1024))
print($line);
Code: Select all
$filename="test.txt";
$lines = file($filename);
foreach($lines as $line)
print($line);
Code: Select all
$filename="test.txt";
while($data = fread($fd, 1024))
print($data);
Code: Select all
$filename="test.txt";
readfile($filename);
all these should read and output a file you have read permissions on.
Posted: Mon Aug 19, 2002 9:38 pm
by Silver_Eclipse
yeah got it to work just cant figure out how to get it to delete the file. and still need to find out how to remove certain lines and input lines in their place.
Posted: Mon Aug 19, 2002 9:42 pm
by volka
using file() you have an array you can work on.
You may walk the array with foreach() writing the lines you want to keep, leaving those you want to delete out or change those you want to alter.
unlink() deletes a file.
Posted: Mon Aug 19, 2002 9:48 pm
by Silver_Eclipse
but with unlink() do i use the filepointer, or just type the file in or what?
Posted: Mon Aug 19, 2002 9:50 pm
by Silver_Eclipse
err doh unlink() failed permission denied on line 25
Posted: Mon Aug 19, 2002 9:52 pm
by Silver_Eclipse
did i mention i am on my own server Apache, with newest version of php.
Posted: Mon Aug 19, 2002 9:54 pm
by volka
int unlink ( string filename) and you (/the script) need(s) write and/or modify permissions.
assuming apache on linux:
What are the owner/group/other permissions on that file.
and what effective uid/gid is your script running under?
Posted: Mon Aug 19, 2002 9:57 pm
by Silver_Eclipse
yeah but my server should have permissions because it reads and writes to the file but wont delete it.
Posted: Mon Aug 19, 2002 9:58 pm
by volka
do you still have an open filedescriptor on that file when you try to delete it?
Posted: Mon Aug 19, 2002 10:00 pm
by Silver_Eclipse
filedescriptor? if thats like an open filepointer i probably do because i cant get fclose to work either argh
Posted: Mon Aug 19, 2002 10:03 pm
by volka
fopen returns an filedescriptor.
Can't use fclose? uhh?
Posted: Mon Aug 19, 2002 10:04 pm
by Silver_Eclipse
Warning: fclose(): 1 is not a valid File-Handle resource in file.php on line 19
Posted: Mon Aug 19, 2002 10:06 pm
by volka
Code: Select all
$filename="test.txt";
$fd = fopen($filename, "rb") or die('failed to open $filename");
while($line = fgets($fd, 1024))
print($line);
fclose($fd);
^ this doesn't work?

Posted: Mon Aug 19, 2002 10:08 pm
by Silver_Eclipse
here's a chunk of my code:
Code: Select all
while(list($array) = each($file)){
if ($array > $a and $array < $b){
fputs ($fe, $fileї$array], 100000);
fclose ($fe);
}