1

I want to run https://github.com/svg/svgo from PHP but have some problems with the permissons.

My Example App:

root
 -- svgo.php
 -- svgfiles
  -- test.svg
 -- node_modules
    -- svgo
      -- bin
        --svgo

My PHP Script:

<?php
  exec("node_modules/svgo/bin/svgo svgfiles/test.svg -o svgfiles/test.min.svg");
?>

When I run on the CLI "php svgo.php" is creates the test.min.svg file, but when I access "localhost/svgo.php" with my MAMP installation it does nothing. I also gave the path "svgfiles" permissons 777.

tiefenb
  • 732
  • 3
  • 16
  • 32
  • What happens if you put `echo` before the `exec`? Maybe it may tell you why it's failing – IsThisJavascript Nov 29 '17 at 10:22
  • the echo will be outputted. If I echo the return of the exec on the command line it will print the result like "test.svg: Done in 42 ms! 8.104 KiB - 40.5% = 4.824 KiB" on localhost the echo from exec is empty... no error or else... – tiefenb Nov 29 '17 at 10:25
  • Try running `echo exec("ls");` to ensure you are actually in the correct directory – IsThisJavascript Nov 29 '17 at 10:30

1 Answers1

1

You have to explicitly tell node to run the svgo library. And use the full path to the binaries.

Example:

exec("/absolute/path/to/node /absolute/path/to/svgo [options] [args]");

custer
  • 26
  • 1