Cant get the PDF open in new browser window. There is a php code I use to set the PDF and open it!
<?php
if (($_POST['name_check']=="in") || ($_GET['type']=="in")){
header('Content-Type: application/pdf; charset=windows-1257');
header("Content-Disposition: inline; ");
header('Accept-Ranges: bytes');
$file_type = "in";
$flag = 0;
}
else{
header('Content-Type: application/pdf; charset=windows-1257');
header("Content-Disposition: inline;");
header('Accept-Ranges: bytes');
$file_type = "out";
$flag = 1;
}
?>
<?php session_start();
if (((isset($_SESSION['UserID'])) and (isset($_SESSION['Pin_code']))) and (isset($_COOKIE['CookieMy']))){
$form='<form action="login.php" method="get" style="width: 900px;margin: -1px auto -57px auto;" class="exit_but">
<input type="submit" name="exit" value="EXIT" style="margin-left: 800px;"></form>';
echo $form;
} else {
header("Location: login.php");
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style1.css" />
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
idleTimer = null;
idleState = false;
idleWait = 1200000;
var theElement = document.getElementById("elem");
$(document).ready(function(){
$(document).bind('mousemove keydown scroll click', function(){
clearTimeout(idleTimer);
idleState = false;
idleTimer = setTimeout(function(){
idleState = true;
window.location.href = "login.php"
}, idleWait);
});
});
</script>
</head>
<body>
<?php
function last(){
if (($_POST['name_check'])=="in"){
$type = '"pdf-in"';
$flag=0;
echo "<script>window.flag_in=false;</script>";
}
else{
$type = '"pdf-out"';
$flag=1;
echo "<script>window.flag_in=true;</script>";
}
if (!isset($aircraftid)){
$aircraftid = $_POST['hostcountry'];
$aircraftid='"'.$aircraftid.'"';
}
if (!isset($date)){
$date = $_POST['per1'];
$date=date($date);
}
include ("config.php");
//////////////////////////////////////////
$mysqli = new mysqli($dbconf['host'], $dbconf['user'], $dbconf['password'], $dbconf['dbname']);
if ($mysqli->connect_errno) {
echo "MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$query = mysqli_multi_query( $mysqli, "SELECT dn_get_flight_file_name($date,$aircraftid,$type);") or die( mysqli_error( $mysqli ) );
if( $query )
{
if ($result = $mysqli->store_result()) {
while ($row = $result->fetch_row()) {
$PDF_File_Name=$row[0];
}
$result->free();
}
}
///////////////////////////////////
mysqli_close( $mysqli );
$qwerty=$PDF_File_Name;
///////////////////////////////////
$ftp .='ftp://'.$ftp_user.':'.$ftp_pwd.'@'.$ftp_server;
if($flag==0){
$file_path_ftp = $ftp_path_pdf_in.$qwerty;
$file_path_local = "in/".$qwerty;
}
else{
$file_path_ftp = $ftp_path_pdf_out.$qwerty;
$file_path_local = "out/".$qwerty;
}
$file_path_ftp = trim($file_path_ftp);
$file_path_local = trim($file_path_local);
$file = $file_path_local;
$current_content = file_get_contents($ftp.$file_path_ftp);
file_put_contents($file, $current_content);
$qwerty=$file_path_local;
$date2 = $_POST['date'];
$num = $_POST['num'];
return array ($qwerty,$date2,$num);
}
if (isset($_GET['name'])){
$qwerty=$_GET['name'];
}
else {
list ($qwerty,$date2,$num) = last();
}
if (!file_exists($qwerty)) {
$file_path_local=$qwerty;
$slash_occur = stripos($qwerty, '/');
$file_type = substr($qwerty, 0, $slash_occur);
$file_name = substr($qwerty, $slash_occur+1);
if($file_type=='pdf-in'){
$file_path_ftp = $ftp_path_pdf_in.$file_name;
}
else{
$file_path_ftp = $ftp_path_pdf_out.$file_name;
}
echo "<h2>file_type = ".$file_type.", file_name = ".$file_name."</h2>";
$ftp .='ftp://'.$ftp_user.':'.$ftp_pwd.'@'.$ftp_server;
$current_content = file_get_contents($ftp.$file_path_ftp);
file_put_contents($qwerty, $current_content);
}
if (isset($_GET['date'])){
$date2=$_GET['date'];
}
if (isset($_GET['num'])){
$num=$_GET['num'];
}
?>
<?php
if (($_POST['name_check']=="in") || ($_GET['type']=="in")){
@readfile($ftp_path_pdf_in.$qwerty);
} else {
@readfile($ftp_path_pdf_out.$qwerty);
}
?>
</body>
</html>
I'm trying to open PDF file in the new (Chrome) browser window.
document.action =window.open('date_PDF.php', 'newWindow', 'width=1000, height=1000');
Error is Failed to load PDF document.
When I do document.getElementById("edit").action ="date_PDF.php";
it opens pdf.
I get the PDF file from the ftp server and than display it on date_PDF.php @readfile($ftp_path_pdf_in.$qwerty);
Where is the problem? Thank you!
</div>