Reputation: 53
i'm trying to make a online editor for a CMS panel. So that if I click on a file online I will get the file returned to me with the PHP/HTML etc. in it. The problem now is that when I use the function stream_get_contents I'm not exactly getting back what I want...
This is my PHP part to get the file:
$fileAdresRoot = $_SERVER['DOCUMENT_ROOT'];
if(empty($_GET['name']))
{
header('Location: ftp-directory');
exit();
}
else
{
$fileName = trim($_GET['name']);
$fileAdres = $fileAdresRoot.'/'.$fileName.'';
}
if(isset($_GET['doublename']))
{
$fileMaps = trim($_GET['doublename']);
$fileAdres = $fileAdresRoot.'/'.$fileMaps.'/'.$fileName.'';
}
$fileContents = fopen($fileAdres, 'rb', false);
$fileContent = stream_get_contents($fileContents);
I'm echoëing $fileContent like this:
<pre id="editor"><?php echo $fileContent; ?></pre>
So it needs to give me this, it needs to show me this:
<?php
$getPage = 'Blog beheren';
include_once 'includes/header.php';
/* Starting with selecting the blog information and post from the database. */
if (isset($_GET["page"])) { $page = trim($_GET["page"]); } else { $page=1; }
$start_from = ($page-1) * 5;
$stmt = $mysqli->prepare("SELECT id, datum, auteur, comments, titel FROM blog ORDER BY id DESC LIMIT ?, 5");
$stmt->bind_param('s', $start_from);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($blogId, $blogDatum, $blogAuteur, $blogComments, $blogTitel);
$intBlog = $mysqli->query("SELECT id FROM blog")->num_rows;
?>
<!-- Matter -->
<div class="matter">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="widget">
<div class="widget-head">
But instead it's showing me this:
prepare("SELECT id,datum,comments,tags,titel,omschrijving,image,auteur FROM blog ORDER BY id DESC LIMIT ?,5");
$stmt->bind_param('i', $start);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($blogId, $blogDate, $blogComments, $blogTags, $blogTitle, $blogDesc, $blogImg, $blogAuth);
$intInfo = $stmt->num_rows;
?>
Home
Blog
Blog
So not only the HTML div's etc will not be shown, but also the
Upvotes: 0
Views: 211
Reputation: 81
I believe what is happening currently is that your string is not being encoded to display as html entities, and so they are being rendered as actual HTML.
With what you are going for, you would want to echo your file contents with the htmlentities function
so it would look something like this:
<?php echo htmlentities($fileContent, ENT_HTML5); ?>
Upvotes: 2