Error while trying to run fwrite in PHP

Asked

Viewed 15 times

0

When trying to execute the fwrite in PHP, I get the following message:

Notice: fwrite(): write of 24 bytes failed with Errno=9 Bad file Descriptor in C: Apache24 htdocs run-php run.php on line 5

The code is as follows::

<?php

$arquivo = fopen('file.txt', 'r');

fwrite($arquivo, 'Conteúdo a ser inserido');

fclose($arquivo);

What is the reason for this error, how can I resolve?

1 answer

0


You are using read mode in function fopen() instead of the writing mode (instead of 'r' should wear 'w'). Check the access modes to a file in the official PHP documentation

  • Thank you, it was inattentive.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.