I have problems opening a text file with php

1

I've been trying to add a text string to a .txt file from php but I get these errors

this is my code:

<?php

$archivo = fopen("fichero_texto.txt", 'a+');

fwrite($archivo, "Soy el texto que añadiste al fichero");

while (!feof($archivo)) {
  $lectura = fgets($archivo);
  echo $lectura, "<br>";
}

fclose($archivo);

At the time of running everything I get these errors: (according to I have assigned the permissions well, I do not know what is failing)

    
asked by Hafid Morales Sanchez 15.12.2018 в 16:55
source

1 answer

1

The error you are getting is because the file you are trying to open does not have enough permissions to read or edit it.

How to change permissions?

There are two commands that will be very useful, first there is chmod that will allow us to modify just such permissions and the another is chown which is used to modify the owner. But most cases are used only chmod .

How to use it?

The easiest way is to give permissions 7 (reading, editing and execution) to the file for all owners, it would be as follows:

$ sudo chmod 777 /ruta/proyecto/archivo.txt

With that you will avoid a headache, but I definitely recommend reading how it works to avoid violating your system because it represents a great risk in uncontrolled environments.

$ sudo chmod 755 /ruta/directorio
$ sudo chmod 644 /ruta/directorio/archivo.txt

Taken from: Diario IFCD0110 Castro Urdiales

    
answered by 15.12.2018 / 17:10
source