Frage

How do i get the source code of a php file hosted on the same server through php code?

Something like this to echo the source code of the php file named file.php.

echo readfile("/var/html/rootpath.com/file.php");

Thanks for any help towards this, i tried file_get_contents but that just gets the html source and not the php file's source code.

War es hilfreich?

Lösung

Make use of fgets()

<?php
$handle = fopen('test.php','r+');
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo htmlentities($buffer);
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}

Assuming your test.php contains a code of

<?php
echo "Hello World";
?>

Andere Tipps

echo file_get_contents("/var/html/rootpath.com/file.php");

http://cz2.php.net/manual/en/function.file-get-contents.php

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top