2

So is there a way to open local file in default program from local browser app?

Tried using simple html a href

file:///filepath/filename.exe

doesn't work due to security policies, says:

Not allowed to load local resource

Tried using php exec

exec('notepad');

Seems like it opens it server-side but not client-side.

Also tried

exec('runas /admin notepad')

Says

Enter the password for admin:

I know there lots of duplicates and I spent some time researching, but cannot find decisive answer is it possible? and if it is, how?

user3221449
  • 71
  • 2
  • 10

3 Answers3

0

Not possible.

PHP is a server side language, no PHP is seen by the client browser.

Furthermore, this can not even be done using a client side browser language such as javascript; reason being, this would be a huge security vulnerability in that it would allow any website you visit to arbitrarily execute / launch applications on your local machine.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • Many thanks for the reply! I'll keep digging in "html / javascript" direction. – user3221449 Jan 25 '17 at 20:11
  • Looking more into myself, it does not even appear as if it will be possible using js, this would be a huge security vulnerability, as it would allow any website you visit to arbitrarily launch applications on your machine. – Matt Clark Jan 25 '17 at 20:13
  • I found the working php solution. Check the thread if you are interested. – user3221449 Jan 25 '17 at 22:06
0

PHP can't be used to start a program client side. Also, javascript is not capable of doing this either: How can I run a program or batch file on the client side? as it would be a security risk.

However there is one way to do it but this can't be used to open every type of file. For example, sending a user the address mailto:example@email.com will prompt the user to open the default program for email. If your program supports this, then you can open it that way. This might not be possible in your use case, but you can make your own protocol like this if you can install something on their computer: https://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx

Community
  • 1
  • 1
EDD
  • 2,070
  • 1
  • 10
  • 23
-3

Hooray, It worked!

Thanks to this guy.

It IS POSSIBLE to run any external GUI program with php with 3 lines of code:

shell_exec('SCHTASKS /F /Create /TN _notepad /TR "notepad.exe" /SC DAILY /RU INTERACTIVE');
shell_exec('SCHTASKS /RUN /TN "_notepad"');
shell_exec('SCHTASKS /DELETE /TN "_notepad" /F');

Basically you are scheduling a task, then running, then deleting it.

Community
  • 1
  • 1
user3221449
  • 71
  • 2
  • 10
  • Sorry to burst your bubble, but: the task you create is running on the server, not locally. (It's no different than `exec()` in this regard -- it's just an unnecessarily complicated way of running the command.) –  Jan 25 '17 at 22:24
  • @duskwuff please tell me any other working way to open local gui program (like excel or vlc) with php? – user3221449 Jan 25 '17 at 22:53
  • You can't. This is an intentional security feature of web browsers. –  Jan 25 '17 at 23:05
  • @duskwuff the initial question was about `local web app` which means server is my local machine and app is accessed via 127.0.0.1. Sorry if my q was not descriptive enough i am not a pro. – user3221449 Jan 25 '17 at 23:13