Page 1 of 1

Php calling stream_get_contents on a php file

Posted: Sun Jul 18, 2010 7:41 pm
by action_owl
I am trying to get the text contents (not execute) a php file on another server via ftp, the process below works for .html files but produces odd results for .php files.

Code: Select all

<?

$host = 'ftp.myhost.com';

$username = 'username';

$password = 'password';

$connection = ftp_connect ( $host );

$result = ftp_login ( $connection, $username, $password );

$handle = fopen( 'php://temp', 'r+' );

$file = './public_html/index.html';

if ( ftp_fget( $connection, $handle, $file, FTP_ASCII, 0 ) )
{
	rewind( $handle );

	$contents = stream_get_contents ( $handle );
}

fclose($handle);

?>
<pre>
Plain: <?= $contents ?>
</pre>

<pre>
Url Encode: <?= urlencode($contents) ?>
</pre>

<pre>
Url Encode then Decode: <?= urldecode( urlencode($contents) ) ?>
</pre>
Output

<pre>
Plain: </pre>

<pre>
Url Encode: %3C%3F%3D+%27hello%27+%3F%3E%0A</pre>

<pre>
Url Encode then Decode: </pre>
Contents of test.php:

Code: Select all

<?= 'hello' ?>
urlencode isn't needed for .html files, just .php

stream_get_contents ( $handle ); seems to have the data it's just encoded differently from .html files