如何使其在PHP中运行`exec()`命令以在Mac OS X中编辑某些文件? [英] How to make it run the `exec()` command in PHP to edit some file in Mac OS X?

查看:189
本文介绍了如何使其在PHP中运行`exec()`命令以在Mac OS X中编辑某些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有这个PHP脚本时.

When I have this PHP script.

<?php
    exec('/usr/local/bin/mate hello.txt');
?>

例如,它在使用 http://abc/hello.php 的网络浏览器上不起作用

It doesn't work on web browser with http://abc/hello.php, for example.

mate的命令是"TextMate app",仅用于编辑hello.txt.

The command of mate is 'TextMate app', and it's just for editing hello.txt.

这是一些php权限问题吗? 我只需要在本地Web服务器上运行一些命令(我是唯一的用户),因此我可以打开运行此看似危险的exec()函数的权限.

Is this some php permission problem? I just need to run some commands on my local web server (I'm the only user), so I can open the permission to run this seemingly dangerous exec() function.

  • Q:如何使其运行PHP exec()函数?

我使用Mac OS X 10.6.6/Apache/PHP5.

I use Mac OS X 10.6.6/Apache/PHP5.

我想不可能在Mac上使用PHP启动某些东西,但是出于我的目的,使用txmt协议打开TextMate编辑器来编辑某些东西,就很好了.

I guess it's not possible to launch something with PHP on my Mac, but for my purposes to open an TextMate editor to edit something, using txmt protocol works perfectly fine.

就在Web浏览器(尤其是Safari)中启动应用程序而言,不能使用php来完成,而只能使用协议处理程序来完成.

In terms of launching an Application in web browser (especially Safari) cannot be done with php, but with protocol handler.

TextEditor提供了自己的协议处理程序txmt://open/?url=file://THE_FILE_TO_EDIT".

TextEditor provides its own protocol handler txmt://open/?url=file://THE_FILE_TO_EDIT".

或者,您可以单击按钮来编辑文件.

Or, you can have a button to edit the file when clicked.

<form action="txmt://open/?url=file://FILE_TO_EDIT" method="post">
  <button type="submit">Edit</button>
</form>

启动其他应用

您需要提出自己的协议处理程序.举例说明了所有必要的信息.

Launching other app

You need to come up with your own protocol handler. has all the necessary information with an example.

例如,用于启动PathFinder

For example, for launching PathFinder

您可能想要弹出的主窗口.您可以设置Application is agent.

You may want to main window that pops up. You can set Application is agent.

它只是分析pf:INPUT_GINVEN的输入,以获取INPUT_GIVEN部分并将其作为PathFInder的参数.

It just analyzes the input of pf:INPUT_GINVEN, to get the INPUT_GIVEN part to give it as a parameter to PathFInder.

@implementation URLHandlerCommand!
- (id)performDefaultImplementation {
    NSString *urlString = [self directParameter];

    NSLog(@"url :=: %@", urlString);

    NSArray *components = [urlString componentsSeparatedByString: @":"];
    NSString* string2 = (NSString*) [components objectAtIndex:1];

    NSLog(@"url :=: %@", string2);

    [[NSWorkspace sharedWorkspace] openFile:string2 withApplication:@"Path Finder"];
    [[NSApplication sharedApplication] terminate:nil];

    return nil;
}

@end

<form action="pf:DIRECORY_TO_OPEN" method="post">
    <button type="submit">Open</button>
</form>

推荐答案

如果脚本在远程Web服务器上运行,则exec()将在远程服务器上运行,不是在本地机器.我的猜测是您希望命令在正在访问该网站的本地计算机上运行,​​但是出于很好的(安全)原因,这是不可能的.

If the script is running on a remote web server, then the exec() will run on the remote server, not the local machine. My guess is you want the command run on the local computer that is visiting the website, but this is not possible for very good (security) reasons.

您可能想使用的是txmt://协议,如 Textmate手册:

What you probably want to use is the txmt:// protocol as described in the Textmate Manual:

<a href="txmt://open/?url=file://~/.bash_profile&line=11&column=2">Open in Textmate</a>

这篇关于如何使其在PHP中运行`exec()`命令以在Mac OS X中编辑某些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆