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

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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度