Get content of php file in PHP

392 Views Asked by At

I'm using ftp_get to get content of a php file from FTP in PHP.

ob_start();
$result = ftp_get($ftp_conn, "php://output", "file.php", FTP_BINARY);
$data = ob_get_contents();
ob_end_clean();

This is file.php

<?php echo "string"; ?>

But it show php code, not content of "echo" in that php file. There any do this?

Thank so much!

2

There are 2 best solutions below

0
Holger On BEST ANSWER

Very ugly, but may succeed

ob_start();
$result = ftp_get($ftp_conn, "localcopy.php", "file.php", FTP_BINARY);
include("localcopy.php");
$data = ob_get_contents();
ob_end_clean();
4
Cooluser On

Replace

$result = ftp_get($ftp_conn, "php://output", "file.php", FTP_BINARY);

With this:

require 'file.php';
$data = ob_get_contents();