Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php exec not executing if called from browser

This is a recurring topic in stackoverflow, but finally I couldn't find any clear solution.

I'VE THIS PHP SCRIPT ON MY LOCAL XAMPP (OS X)

test.php

<?php exec('lpr -MyPrinter photos/image.jpg'); ?>

IT WORKS IF I CALL IT FROM TERMINAL

kurt$ php test.php

BUT IT DOES NOT WORK IF I CALL IT FROM BROWSER

http://localhost/mysite/test.php

Consider that my security requirements are very low, because I'll use this script locally only for personal purposes. Can you address me to the right solution?

like image 438
Martin Devarda Avatar asked Mar 11 '26 04:03

Martin Devarda


1 Answers

Could have any number of reasons, but I suggest to look at the error message. The exec() function will not return it, but you can redirect error output to a temporary file:

<?php exec('lpr -MyPrinter photos/image.jpg 2> /tmp/error.txt'); ?>

Look into /tmp/error.txt after calling the script in the browser.

like image 130
Wolfgang Stengel Avatar answered Mar 12 '26 18:03

Wolfgang Stengel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!