[eluser]rochellecanale[/eluser]
Hello guys I have a little problem here about download helper. My problem is after i created a file that can generate a POS receipt. And I used a download helper. The sequence is:
1. Get details about purchased products (done automatically)
2. Save it in notepad inside my receipt folder (done automatically)
3. After saving there is a button named "PRINT RECEIPT" (need to click the button for printing)
4. Click the button and it will automatically call the
function for downloading.
5. After downloading the next line in my code is an exec() function that calls the printer
6. After the exec() function the printer should print the desired file.
Here's my sample code:
Code:
//receipt.php
$date = date('YmdHis');
$myFile = "c:/receipt/receipt".$date.".txt";
$sec_file = "receipt".$date.".txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Thank you for transacting at ".PHP_EOL."High5 Cellular Tech Solutions".PHP_EOL;
fwrite($fh, $stringData);
$stringData = date('M d, Y H:i:s A').PHP_EOL;
fwrite($fh, $stringData);
.
.
.
.
fclose($fh);
echo "<tr>";
echo "<td colspan='2'>";
echo form_open('sales_controller/testprint');
echo "<input type='hidden' name='url' value = {$sec_file}>";
echo "<input type='submit' value='PRINT RECEIPT' />"; // the button
echo form_close();
echo "</td>";
echo "</tr>";
//my controller function
public function testprint(){
$data['url'] = $this->input->post('url');
$this->load->view('sites/testprint123',$data);
}
//testprint123.php
$code = "PRINT-".date('YmdhisA').".txt";
$data2 = file_get_contents("c:/receipt/".$url); // Read the file's contents
$name2 = $code;
force_download($name2, $data2); //after this function it can't proceed to the next line
//not running
$directory = "C:/Documents and Settings/New user/My Documents/Downloads/".$code;
$printer = "CSO_PRINTER";
exec('NOTEPAD.EXE /PT "'.$directory.'" "'.$printer.'"');
My problem is in testprint123.php, after the download it can't proceed to the next line or next code. That's why I can't print the receipt.