Echo file with php tags

0

I'm developing an intra net portal for the company I work in, I'm using a central page and searching for the content of other pages via ajax, the other pages are outside the public_html folder so I use a controller to return the contents of these pages instead of jquery pulling.

The problem is that several of these pages will have content in php, using the tags, I am currently trying to use the file_get_contents but when I give echo of the result the server does not process the php codes, it echoes with the tas.

Can anyone guide me in getting a controller to read and process php code from another file and return the result?

Controller function

public function inclusion($data){
        try{
            $dir = $data[1]->value;
            $file = $data[2]->value;
            if(!file_exists('../pages/'.$dir)) throw new Exception('Pasta não encontrada.'.$dir);
            if(!file_exists('../pages/'.$dir.'/'.$file.'.php')) throw new Exception('Arquivo não encontrada.'.$file);
            $result = file_get_contents('../pages/'.$dir.'/'.$file.'.php');
            $response = [
                'success'=>[
                    'return'=>$result
                ]
            ];
            echo json_encode($response);
        }catch(Exception $er){
            throw $er;
        }
    }

Sample file to be read in $ result

<h1>Erro Page </h1>
<div class="content_in">
    Teste erro<p><?php echo '1'; ?></p>
</div> 
    
asked by anonymous 31.10.2017 / 17:12

1 answer

0
<?php

function result(){
    /* Crie uma funcao aqui */
    $return = '<h1>Erro Page </h1><div class="content_in">Teste erro<p><?php echo "1"; ?></p></div>';

    return $return;
}

function inclusion($data)
{
    try {
        $dir = $data[1]->value;
        $file = $data[2]->value;
        if (!file_exists('../pages/' . $dir)) {
            throw new Exception('Pasta não encontrada.' . $dir);
        }
        if (!file_exists('../pages/' . $dir . '/' . $file . '.php')) {
            throw new Exception('Arquivo não encontrada.' . $file);
        }

        $result = result();
        $response = [
            'success' => [
                'return' => $result
            ]
        ];
        echo json_encode($response);
    } catch (Exception $er) {
        throw $er;
    }
}
    
31.10.2017 / 17:25