简体   繁体   中英

Running SVGO from PHP doens't work with MAMP

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.

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]");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM