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.
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']);
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.