Create .php files with fopen ()

0

I'm Trying this:

<a href="
<?php
$fh = fopen($p['n'].php, 'w') or die("Can't create file");
if($fh)
{
$code ="
<?php
//codigo combinado con html nada complejo incluí php para manejar sesiones
?>";
echo fwrite($file,$code); 
    fclose($file); 
}?>"></a>

The problem is that it evaluates the code within $code instead of just passing it as a string

    
asked by ger 20.03.2018 в 15:19
source

2 answers

0

The problem is that I have 2 errors that are at the moment of entering the string in $code

  
  • I forgot that for the string to be saved without evaluation, it should be done with a single comma like this:
  •   

    $code = 'hola';

         

    not with a double quote like this:

         

    $code= "hola";

         
  • As there are several lines you should do with EOD like this:
  •   

    $code = <<<'EOD' codigo con muchas lineas EOD;

    This is how I managed to make the content of $code not evaluated

        
    answered by 20.03.2018 / 17:37
    source
    0

    You can try with the following code:

    $nombre_archivo = 'archivo.php';
    
    $mensaje = "El Archivo $nombre_archivo se ha creado";
    
    if($archivo = fopen($nombre_archivo, "a"))
    {
        if(fwrite($archivo, date("d m Y H:m:s"). " ". $mensaje. "\n"))
        {
            echo "Se ha ejecutado correctamente";
        }
        else
        {
            echo "Ha habido un problema al crear el archivo";
        }
    
        fclose($archivo);
    }
    
        
    answered by 20.03.2018 в 17:21