loilo/native-open

从PHP内部打开文件/URL/应用程序,跨平台

1.0.0 2019-08-19 08:43 UTC

This package is auto-updated.

Last update: 2024-09-09 20:04:32 UTC


README

native-open logo: A mouse pointer, presented as a hand with extended index finger, floating above a colored circle representing an interactive area.

Native Open

此包允许您从PHP内部打开文件/URL/应用程序,跨平台。

请注意,它将在运行PHP代码的机器上打开应用程序,因此您不能用它代表您网站的用户打开应用程序。

此包的大部分功劳归功于 Sindre Sorhus,因为这是他Node.js包 open 的主要移植。

安装

composer require loilo/native-open

用法

use Loilo\NativeOpen\NativeOpen;

// Opens the image in the default image viewer
NativeOpen::open('picture.jpg'); 

// Opens the URL in the default browser
NativeOpen::open('https://github.com/loilo');

// Opens the URL in a specified browser
NativeOpen::open('https://github.com/loilo', 'firefox');

// Specify app arguments
NativeOpen::open('https://github.com/loilo', 'google chrome', ['--incognito']);

此包在macOS上使用open命令,在Windows上使用start,在其他平台上使用xdg-open。请注意,如果您定义了特定应用程序来打开目标,则应用程序名称依赖于平台。不要在可重用模块中硬编码它。例如,Chrome在macOS上是google chrome,在Linux上是google-chrome,在Windows上是chrome