wkhtmltoimage在cli中工作但不在浏览器中工作

时间:2014-11-06 08:11:45

标签: php wkhtmltopdf

当我使用$ php test.php在cli中运行脚本时,图像会很好。下面是php脚本。

require_once 'vendor/autoload.php';

use Knp\Snappy\Image;

$snappy = new Image(APP_PATH . 'vendor/bin/wkhtmltoimage-amd64');
$snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', APP_PATH . 'test.jpg');

当我在浏览器中调用该文件时,出现以下错误。

Warning: file_put_contents(/tmp/php/domain.dev/knp_snappy545b2790c0b664.98469880.html): failed to open stream:
  No such file or directory in /vagrant/sites/clients/domain.dev/public/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php on line 332
Fatal error: Uncaught exception 'RuntimeException' with message
  'The file '/vagrant/sites/clients/domain.dev/public/includes/../test.jpg' was not created
  (command: /vagrant/sites/clients/domain.dev/public/includes/../vendor/bin/wkhtmltoimage-amd64 --format 'jpg'
    '/tmp/php/domain.dev/knp_snappy545b2790c0b664.98469880.html'
    '/vagrant/sites/clients/domain.dev/public/includes/../test.jpg').'
in /vagrant/sites/clients/domain.dev/public/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php:276
Stack trace:
  #0 /vagrant/sites/clients/domain.dev/public/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(132): Knp\Snappy\AbstractGenerator->checkOutput('/vagrant/sites/...', '/vagrant/sites/...')
  #1 /vagrant/sites/clients/domain.dev/public/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php(142): Knp\Snappy\AbstractGenerator->generate('/tmp/php/snowma...', '/vagrant/sites/...', Array, false)
  #2 /vagrant/sites/clients/domain.dev/public/test.php(9): Knp\Snappy\AbstractGenerator->generateFromHtml('
in /vagrant/sites/clients/domain.dev/public/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php on line 276

尝试使用不同权限设置/ tmp文件权限的各种流浪汉配置,认为它在那里。但是从cli到浏览器的权限会有什么不同呢?

0 个答案:

没有答案