3

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?

4
  • 1
    bet its i user permission issue, but dont know how os x does such things Commented Nov 8, 2012 at 18:28
  • 1
    Adding to @Dagon's comment, check the user and group that your script is running as when executed by your server. I'm also not exactly sure how users/groups/permissions are handled on OSX, but your server is probably executing the scripts as a user created specifically for the server, which will have restricted permissions. Commented Nov 8, 2012 at 18:43
  • @G-Nugget whoami returns "nobody" when called from browser Commented Nov 8, 2012 at 19:31
  • 1
    Also not sure about osx, but quite often php cli (command line interface) has a different php.ini. It is possible that the cli php.ini has exec enabled, while the web php.ini has not. Commented Nov 9, 2012 at 12:36

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.