fwrite - f(write) php doesn't seem to work

488
$abc = @fopen("$DOCUMENT_ROOT/../public_html/zamowienia.txt",'ab');
if(!$abc)
{
     echo "<br /><br />Zamowienie Panstwa nie moze zostac przyjete w tej chwili. Prosze sprobowac pozniej.";
}
$ciagwyjsciowy = $CPU."\t".$Cenazamowienia_netto."\t".$Cenazamowienia_brutto."\n";
fwrite($abc, $ciagwyjsciowy);
fclose($abc);

this warning will display

Warning: fwrite(): supplied argument is not a valid stream resource in /home/a6907098/public_html/Sklep/process.php on line 27

What's wrong with the code?

PHP Error Message

Warning: fclose(): supplied argument is not a valid stream resource in /home/a6907098/public_html/Sklep/process.php on line 28
979

Answer

Solution:

using @ in fopen will make file handler to return 0 errors, which means if your file wasnt opened, there will be no error returned. replace @fopen with fopen.

534

Answer

Solution:

try this

$abc = fopen("$DOCUMENT_ROOT/../public_html/zamowienia.txt",'a');
if(!$abc)
{
     echo "<br /><br />Zamowienie Panstwa nie moze zostac przyjete w tej chwili. Prosze sprobowac pozniej.";
}
else
{
  $ciagwyjsciowy = $CPU."\t".$Cenazamowienia_netto."\t".$Cenazamowienia_brutto."\n";
   fwrite($abc, $ciagwyjsciowy);
   fclose($abc);
}

and see what happened. i hope you will find solution

952

Answer

Solution:

You get this error because your $abc variable it's "is not a valid stream resource" Maybe something wrong with your path to file.

Try this please:

$abc = fopen("$DOCUMENT_ROOT/../public_html/zamowienia.txt",'ab');
if(!$abc)
{
     die("<br /><br />Zamowienie Panstwa nie moze zostac przyjete w tej chwili. Prosze sprobowac pozniej.");

}else{
    $ciagwyjsciowy = $CPU."\t".$Cenazamowienia_netto."\t".$Cenazamowienia_brutto."\n";
    fwrite($abc, $ciagwyjsciowy);
    fclose($abc);
}

I'm sorry but code looks awful :(

748

Answer

Solution:

Did you mean$_SERVER['DOCUMENT_ROOT'] instead of$DOCUMENT_ROOT ?

Also if you get printedZamowienie Panstwa nie moze zostac przyjete w tej chwili. Prosze sprobowac pozniej. it means that you got no file pointer so you can try Satish Sharma answer.

People are also looking for solutions to the problem: PHP Adding 2 decimal points numbers (money) gives wrong results in total amount

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.