2016-09-30 19:37
浏览 116

PHP PhantomJS无法使截图目录可写

I am trying to capture a screen and save it locally. When I run the code it shoots me an error message

Fatal error: Uncaught JonnyW\PhantomJs\Exception\NotWritableException: Output file is not writeable by PhantomJs:

This is my code

require 'vendor/autoload.php';

use JonnyW\PhantomJs\Client;

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

$client = Client::getInstance();
// $client->getEngine()->setPath('/usr/local/bin/phantomjs');

$width  = 800;
$height = 600;
$top    = 0;
$left   = 0;

 * @see JonnyW\PhantomJs\Http\CaptureRequest
$request = $client->getMessageFactory()->createCaptureRequest('http://jonnyw.me');
$request->setViewportSize($width, $height);
$request->setCaptureDimensions($width, $height, $top, $left);

 * @see JonnyW\PhantomJs\Http\Response 
$response = $client->getMessageFactory()->createResponse();

// Send the request
$client->send($request, $response);


And this is my form

<!DOCTYPE html>
    <title>Upload Files to Crop/Take Screenshot of URL</title>

  <h1>TAKE SCREENSHOT OF URL WITH phantomjs <span style="color:red">[NOT WORKING YET!!!!]</span></h1>
  <form enctype="multipart/form-data" method="post" action="phantomjs.php">
    <div class="row">
      <label for="siteToCapture">Site to Capture</label><br />
      https://www.<input type="input" name="siteToCapture" id="siteToCapture" />.com
    <div class="row">
      <input type="submit" value="SCAN" />


Another interesting thing I noticed was if I removed the '/' before screenshot/TEST.jpg I receive a blank page with no errors and still no screenshot.

I have also created the screenshot folder in the root directory.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试捕获屏幕并将其保存在本地。 当我运行代码时,它会向我发送错误消息

致命错误:未捕获JonnyW \ PhantomJs \ Exception \ NotWritableException:输出文件不能由PhantomJs写入:


require'proforts / autoload.php'; 
use  JonnyW \ PhantomJs \ Client; 
 $ client = Client :: getInstance(); 
  // $ client-&gt; getEngine() - &gt; setPath('/ usr / local / bin / phantomjs'); 
 $ width = 800; 
 $ height = 600; 
 $ top = 0;  
 $ left = 0; 
 / ** 
 * @see JonnyW \ PhantomJs \ Http \ CaptureRequest 
 ** / 
 $ request = $ client-&gt; getMessageFactory() - &gt; createCaptureRequest('  http://jonnyw.me'); 
 $ request-&gt; setOutputFile('/ screenshot / TEST.jpg'); 
 $ request-&gt; setViewportSize($ width,$ height); 
 $ request-  &gt; setCaptureDimensions($ width,$ height,$ top,$ left); 
 / ** 
 * @see JonnyW \ PhantomJs \ Http \ Response 
 ** / 
 $ response = $ client-&gt  ; getMessageFactory  () - &gt; createResponse(); 
 $ client-&gt; send($ request,$ response); 


 &lt;!DOCTYPE html&gt; 
&lt; html&gt; 
&lt; head&gt; 
&lt; title&gt;上传 要裁剪的文件/截取网址&lt; / title&gt; 
&lt; / head&gt; 
&lt; body&gt;的屏幕截图 
&lt; h1&gt;使用phantomjs&lt; span style =“color:red”&gt; [NOT WORKING YET !!!!]&lt; / span&gt;&lt; / h1&gt; 
&lt;表格屏幕截图 enctype =“multipart / form-data”method =“post”action =“phantomjs.php”&gt; 
&lt; div class =“row”&gt; 
&lt; label for =“siteToCapture”&gt; Site to Capture&lt  ; / label&gt;&lt; br /&gt; 
 https://www.< input type =“input”name =“siteToCapture”id =“siteToCapture”/>.com
&lt; / div&gt; 
  &lt; div class =“row”&gt; 
&lt; input type =“submit”value =“SCAN”/&gt; 
&lt; / div&gt; 
&lt; / form&gt; 
&lt; / body&gt;  
&lt; / html&gt; 

我注意到的另一个有趣的事情是,如果我在截屏/ TEST.jpg之前删除了'/',我会收到一个没有错误的空白页面 仍然没有截图。


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqishou7471 2016-09-30 20:32

    Look, you are trying to write screenshot to /screenshot/ folder. And the path is absolute. So make sure you have /screenshot/ folder in the root of your disk and script can write to it.

    There are two kinds of paths: absolute and relative.

    First one, is path that is starts from the root of your disk and it always starts from / character, like this: /usr/local/bin/phantomjs.

    Second one is the path which relative to your current working dirrectory, it can starts with ./ characters, or ../, or just some/folder/. So, in your case, if you have screenshots folder within your current working directory, you should specify output file like this:


    Notice the dot char at the beginning.

    解决 无用
    打赏 举报

相关推荐 更多相似问题