I am trying to read the most recent file from the folder. After finding the latest file, I'm reading it line by line and printing it on the barcode printer using barcode Overprinter software. This barcode printer is the default printer on my server.
Here is my PHP code:
<?php
$files = glob('C:\barcode\*.*');
$files = array_combine($files, array_map('filectime', $files));
arsort($files);
echo key($files); // for testing
$handle = @fopen(key($files), "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
echo $buffer; // for testing
$retval=passthru("BarcodeGenerator.exe ".$buffer.",,Code128,0");
// based on http://www.free-barcode.com/CommandLineBarcode.htm
echo $retval;
}
if (!feof($handle)) {
echo "Error:\n";
}
fclose($handle);
}
?>
The above command line runs fine in my command line prompt but it doesn't in php script. The program hangs. Nothing happens. If I comment the passthru line, everything is fine. The program executes.
Here is what I've tried so far:
calcs /g BarcodeGenerator.exe everyone:Fsystem(), shell_exec() and exec() toosafe_mode_include_dir") with single quotes ('). C:\\wamp\\www\\)The commands run fine in a command prompt.
So, is there any way to run the shell_exec command as administrator under PHP? It doesn't seem to want to run an executable at all (not only this one). I'm running WAMP on Windows 7.
For example, shell_exec('dir') works fine, but shell_exec('java') doesn't. Why not?
Since you can't run any executables, like Java, this is definitely a permissions problem. The solution, while not recommended for a production server due to security, is to run your WAMP server as administrator.
See this link for details on how to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With