Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loilo/native-open
Open a file/URL/app from inside PHP, cross-platform
https://github.com/loilo/native-open
Last synced: about 23 hours ago
JSON representation
Open a file/URL/app from inside PHP, cross-platform
- Host: GitHub
- URL: https://github.com/loilo/native-open
- Owner: loilo
- License: mit
- Created: 2019-08-19T08:40:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-09T11:50:19.000Z (about 4 years ago)
- Last Synced: 2025-01-31T10:17:03.525Z (21 days ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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](https://sindresorhus.com) as this is mostly a port of his [`open`](https://www.npmjs.com/package/open) package for Node.js.
## Installation
```bash
composer require loilo/native-open
```## Usage
```php
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.