I have a file - filedata.php. The file shows only a CLICK ME
link when opened in the browser. On clicking the CLICK ME
link a popup window should appear which has the source code of filedata.php. I wrote the following code but it isn't working (no pop-up window appears). Please help me to figure out the error.
SCRIPT -
<!DOCTYPE html>
<html>
<script src="jquery-1.9.1.js"></script>
<script>
$(document).ready(function() {
$("a.xy").click(function (event) {
//Prevent default behavior
event.preventDefault();
var js_array = <?php echo json_encode($php_array) ?>;
var disp = window.open('','','width=400,height=400');
$(disp.document.body).text( js_array.join("\n") );
});
});
</script>
PHP CODE -
<?php
// Get a file into an array.
echo '<a href="" class="xy" onclick="openWin()">CLICK ME!</a><br>';
$path='C:\wamp\www\directory_listing\filedata.php';
$lines = file($path);
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
$php_array[$line_num]="Line <b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />";
}
$html = implode('', file($path));
$trimmed = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
</html>