使用 php shell_exec 和 mac osx 终端命令屏幕截图时保存图像吗?
我正在尝试 shell_exec 和命令,但我似乎无法完成这项工作。我使用 php shell_exec() 函数并运行屏幕捕获命令来拍摄桌面快照。当通过 coda 在本地运行脚本时,它工作正常。然后我通过 htdocs 安装 apache 来运行它,它运行了,但它没有将图像保存在任何地方?对于浏览器,我是否需要更改目录?这就是我的超级简单脚本的样子。这可能吗?
<?
$command = "screencapture -iWP ~/Random/test.png";
shell_exec($command);
?>
I was experimenting with shell_exec and commands, and I can't seem to get this work. Im using the php shell_exec() function and running a screen capture command to take a snapshot of the desktop. When running the script locally through coda, it works fine. Then i ran it through my installion of apache through htdocs, and it runs, yet it doesn't save the image anywhere? For browsers, do i need to change the directory at all? this is what my super simple script looks like. Is this even possible?
<?
$command = "screencapture -iWP ~/Random/test.png";
shell_exec($command);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我目前无法使用 Mac 进行测试,但我会感到非常惊讶,并且非常担心这是否有效。
在服务器上,apache 应该在与登录用户不同的用户 ID 下运行,这意味着获取帧缓冲区的尝试应该会失败。
如果它至少写入(或尝试写入)图像,那么它将是 ~/Random/test.png;例如,如果 apache 作为名为 apache 的用户运行,则目标文件名为 ~apache/Random/test.png
OSX 基本上是 UNIX,并且类 UNIX 操作系统的一个关键功能是安全性。视频帧缓冲区只能由在登录用户(或 root)的 UID 下运行的进程访问。像 apache httpd 这样的守护进程应该在它们自己的非 root UID 下运行。
I don't currently have access to a Mac to test, but I'd be extremely surprised and more than a little concerned if that did work.
On the server, apache should be running under a different user ID to the logged in user, which means the attempt to grab the framebuffer should fail.
If it did at least write (or try to write) an image, then it will be ~/Random/test.png; e.g. if apache runs as a user called apache, the target filename is ~apache/Random/test.png
OSX is basically UNIX, and a key feature of UNIX-like operating systems is security. The video framebuffer should only be accessible to processes running under the UID of the logged in user (or root). Daemon processes like apache httpd should be running under their own, non-root UID.
您可能必须指定可执行文件的完整路径。此外,指定输出 PNG 的完整路径也会有所帮助,因为他们是不同的用户。
运行命令
查找可执行文件所在的路径。输出文件必须位于运行 apache 的用户(通常是 apache)的可写目录中。您可以通过查看 apache 配置来检查 apache 正在运行的用户,或者只运行“top”(作为 root)。
希望有帮助。
You probably have to specify the full path of the executable. Also, specifying the full path of the output PNG would help too because they're different users.
Run the command
To find the path that the executable is located in. The output file must be in a writable directory for the user that apache is running under (usually apache). You can check the user that apache is running under by looking in the apache configuration, or just running "top" (as root).
Hope that helps.