Autor Zpráva
Mody
Profil
Ahoj. Mám takový to skript:

index.php

<html>
<body>
<?php
$soubor = fopen("soubor.txt", "r");
$text = fread($soubor, filesize($soubor));
echo($text);
fclose($soubor);
>?>

</body>
</html>


a pak soubor.txt

Ahoj lidičky


- mělo by mi to vypsat obsah toho souboru ale píše mi to chybu:

Warning: stat failed for Resource id #1 (errno=2 - No such file or directory) in c:\apache\htdocs\moje_php\vypsani_souboru.php on line 5

je to podle : tohoto
Matty
Profil
Mody
>?>
To je tam asi navíc.
Jinak, snažší je použít file_get_contents().
Mody
Profil
Matty


<html>
<body>
<?php
$soubor = fopen("soubor.txt", "r");
$text = fread($soubor, filesize($soubor)); - takže místo tohoto??
echo($text);
fclose($soubor);
?>

</body>
</html>
Matty
Profil
Mody
Ne.
<?php
file_get_contents('soubor.txt');
?>
Mody
Profil
To my zase hlásí:

Fatal error: Call to undefined function: file_get_contents() in c:\apache\htdocs\moje_php\vypsani_souboru.php on line 4

netušim kde mám chybu je to i stím tvým matty
BetaCam
Profil
Mody

Fatal error: Call to undefined function: file_get_contents() in c:\apache\htdocs\moje_php\vypsani_souboru.php on line 4

No typnul bych, že nenáš php5.
starenka
Profil
jinak ta puvodni chyba ti rika, ze nemuze nacist ten soubor.... podle toho, jak to mas napsany ten soubor musi bejt ve stejnym adresari jako skript
Mody
Profil
ten soubor tam je to už jsem kontroloval
starenka
Profil
tak evidentne ti vadi, ze to nemuze zjistit velikost souboru....

pokud teda nemas php5 (na localhostu uprimne nechapu), tak si to nacti treba takhle:

$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}


nevim lidi, ale zkuste nejdriv cist MANUAL, nez se na neco ptate...

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0