dqrnskni67375 2016-09-30 19:37
浏览 156
已采纳

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

<?php
require 'vendor/autoload.php';

use JonnyW\PhantomJs\Client;

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

$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->setOutputFile('/screenshot/TEST.jpg');
$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>
<html>
<head>
    <title>Upload Files to Crop/Take Screenshot of URL</title>
</head>
<body> 

  <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>
    <div class="row">
      <input type="submit" value="SCAN" />
    </div>
  </form>

</body>
</html>

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.

  • 写回答

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:

    $request->setOutputFile('./screenshot/TEST.jpg');
    

    Notice the dot char at the beginning.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?