I’m writing a simple order system where several numbers (filled in inside a form) are written to another .php file (may be .html also), using the fopen function. This works fine, but after writing to the file, I want the browser to actually open that written file, preferably in a new browser window. This way my client can use this to print, use as an invoice, etc.
Now I’m still a rookie on php grounds and am not experienced with the use of fopen. But everywhere I look for tutorials etc., it’s said that fopen opens (or writes of course) a file, but it doesn’t for as far as I’ve experienced. It just seems to allow access to the specified file to write and read, rather to actually display the newly written page.
To avoid any confusion: I do NOT want to open links like other questions here on SO state.
My code:
<form action="" method="post">
<input type="text" id="amountTuna" name="numberTuna" value="0"/>
<input type="text" id="amountCheese" name="numberCheese" value="0"/>
<input name="send" id="send" type="submit" value="Post order" />
</form>
<?php
if (array_key_exists('send', $_POST)) {
$order = "order.php";
$fh = fopen($order, 'w') or die("can't open file");//file handler
fwrite($fh, "Tuna sandwiches: " . stripslashes($_POST['numberTuna']));
fwrite($fh, "Cheese sandwiches: " . stripslashes($_POST['numberCheese']));
$fh = fopen($factuur, 'r');
$fileip = fread($fh, filesize($factuur));
fclose($fh);
}
?>
Trying different fopen parameters such as 'w','r','r+' etc doesn’t seem to make any difference. Removing fclose($fh) doesn’t seem to make any difference either.
Use JS script to open new window. For example right after
fclose($fh):