ca hoang
ca hoang

Reputation: 59

Get content of php file in PHP

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!

Upvotes: 0

Views: 444

Answers (2)

Cooluser
Cooluser

Reputation: 1

Replace

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

With this:

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

Upvotes: 0

Holger
Holger

Reputation: 919

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();

Upvotes: 2

Related Questions