loilo / native-open
Open a file/URL/app from inside PHP, cross-platform
Requires
- php: >= 7.1
- loilo/node-path: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-12-09 20:39:23 UTC
README
Native Open
This package enables you to open a file/URL/app from inside PHP, cross-platform.
Note that it opens the app on the machine running the PHP code, so you can not use it to open apps on behalf of your website's users.
Most of the credit for this package goes to Sindre Sorhus as this is mostly a port of his
open
package for Node.js.
Installation
composer require loilo/native-open
Usage
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']);
This package uses the open
command on macOS, start
on Windows and xdg-open
on other platforms. Note that, if you define a specific app to open a target in, the app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is google chrome
on macOS, google-chrome
on Linux and chrome
on Windows.