Page 1 of 1
file_Get_contents() not working.
Posted: Sun Sep 17, 2006 3:53 pm
by toasty2
file_get_contents() doesnt work for me.
Code: Select all
<?php $filename="l.txt"; $file = file_get_contents($filename); echo $file; ?>
Is returning a blank page. I've never used file_get_contents before.
Posted: Sun Sep 17, 2006 3:54 pm
by feyd
$filename comes from..?
Posted: Sun Sep 17, 2006 3:57 pm
by toasty2
I added it. And I did have filename specified in my test script, that's just sort of a snippet from it.
Posted: Sun Sep 17, 2006 4:03 pm
by toasty2
Ok, now it works since I changed some stuff. But, it is displaying the contents twice. The file contains "1" but it is showing me "11"...?
Here's where I tried both readfile and file_get_contents:
Code: Select all
echo "file_get_contents:" . file_get_contents("l.txt");
echo "<Br>readfile:" . readfile("l.txt");
Output:
Posted: Sun Sep 17, 2006 4:34 pm
by volka
When is readfile() executed?
What does it return? (rhethorical questions)
try
Code: Select all
echo "file_get_contents -|" . file_get_contents("l.txt") . "|-<br />\n";
echo "readfile: -|" . readfile("l.txt") . "|-<br />\n"-;
Posted: Sun Sep 17, 2006 4:48 pm
by toasty2
Code: Select all
file_get_contents -|1|-
1readfile: -|1|-
Thats the output. And notice that 1 before readfile?
By the way, I removed the "-" before your last semicolon, that provided an error
I have no problem using readfile instead of file_get_contents, but I am curious as to why it displays the output twice.
Posted: Sun Sep 17, 2006 5:03 pm
by feyd
Change the file's contents to "2" .. maybe that will illuminate the results better.
Posted: Sun Sep 17, 2006 5:11 pm
by toasty2
Output from volka's script with L.txt's contents changed to 2:
Code: Select all
file_get_contents -|2|-
2readfile: -|1|-
WEIRD!

Posted: Sun Sep 17, 2006 5:19 pm
by volka
No, not weird. Just what readfile does: It outputs the file's content immediatly.
file_get_contents returns the content as string, readfile outputs it and returns how many bytes it read (see manual link).
Posted: Sun Sep 17, 2006 5:22 pm
by toasty2
OH, dangit. Well, from my understanding, doesn't file_get_contents put the file into an array? What If I want it in a string?
Posted: Sun Sep 17, 2006 5:28 pm
by volka
doesn't file_get_contents put the file into an array?
The output of the test script would be
file_get_contents -|Array|-
file_get_contents returns....
Posted: Sun Sep 17, 2006 5:32 pm
by toasty2
Nevermind, it works fine
Thanks volka and feyd.