Opening windows application (media player) using php - php

I have written a .php script. When there is some event, it writes to a file. It's working perfectly!
Now I want to open Windows Media Player or any other player using this php script as I also want to play a sound when the event occurs. I tried embedding the sound file as follow:
echo "< embed src =\"$file\" hidden=\"true\" autostart=\"true\">";
But it only writes to the file n do not play the audio, when the event occurs.
I came across 'exec' command which didnt work. (I am not sure about how it works. An example would be a great help!)
Does anyone know how to start a windows application using php script?
EDIT REMOVED
Thanks,
Sagar.

You can play a wave file in your server side folder in a php file by adding this
<?php exec('c:\windows\system32\cmd.exe /c START C:\website\beep.wav');
?>
and this would play the beep.wav usually through whatever sound appy is installed on your machine, like windows media player.

You cannot start console based application through Apache+PHP application. The reason is, as Apache webserver is running as a system service in a separate logon session, it cannot start UI based applications which requires a login console session.
Anyway, you can embed the audio inside the html page. Refer the http://www.w3schools.com/html/html_sounds.asp page to get more details.

Comment about running Windows GUI programs using PHP: http://www.php.net/manual/en/book.exec.php#87943
But, I think you only need to embed player on your page using some HTML tag as Aravind described.

SagarJ,
You can embed the audio file in html and will be executed by the browser/browser plugin application already installed in the system.
So, you need not to worry about that.

Related

Problems rendering and previewing PHP files in the browser

could you help me to troubleshoot why I suddenly can’t render PHP files in my browser or the preview pane of my text editor (Panic Coda) please?
I use a combination of PHP scripts and the Smarty templating engine to write html files for email newsletters. Up until midday today, when I use the Coda preview to run the PHP scripts, the layout renders fine and the html file writing included in the script also worked.
But then suddenly, when I preview the file, all I see is the PHP script in the preview pane – see screen shot.
This happens occasionally, but it is usually enough to quit the application and start it up again, or restart the computer. But not this time.
Apache is on? Check.
Updated to macOS Sierra? Not yet.
No other substantial systems changes? Not that I can think of. Certainly none in the last few hours.
It was this:
Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php
found here: PHP code is not being executed, instead code shows on the page

POS: get a website to print directly to a defined local printer/s

I have a website which runs a box office service which issues tickets and reports. I am trying to figure out how to get tickets (currently PDFs) sent directly to a specified printer on a local/client PC.
I have followed many old/dead/useless links and have not found any up-to-date solutions to this although many tantalising glimmers of hope.
The scenario is this: Remote hosted website - 1 or more users connected - web page generates ticket/s (PDF) which is sent to a specified printer on the user pc (not the default printer) silently (no extra clicking through of print prompts).
I know PHP does not connect to a clients pc but is there a way for a web page (via jQuery perhaps) to connect to an installed script/service?
I was thinking the script on a local PC (which establishes a trusted link, sets the printer to use, etc) would receive data/file from the web server and then process it as long as it was in the same place on every machine. This (local) script then can be added to any PC that needs to run the service. The work would need to be trigged by the file being sent and not having a script/service which is sat polling a location every few seconds.
Any pointers would be greatly appreciated.
Edit: I have tried the jZebra java applet but only got it printing once before it broke. Interested if anyone has actually got it to work (and how).
I ran into the EXACT same question recently myself. Google Chrome has what's called a "kiosk" mode. Therefore, it will print without user intervention.
To do this, open Google Chrome with the following command (you need to find the chrome executable, or chrome command for *nix machines):
chrome.exe "http://www.example.com/mypage.php" --kiosk --kiosk-printing
This will open a window without any toolbars, address bars, omniboxes, etc.
Next, you need to make a page print. To do this, automatically open a print dialog (for demonstration, I'll use simple Javascript):
<script>
window.print();
</script>
Before you jump over to your development environment, window.print() does NOT allow any arguments (i.e. a URL).
This code opens a print dialog. However, in kiosk mode, the print dialog will be bypassed, and the page will be automatically printed to the default printer.
Now you mentioned a PDF, and chances are, your generating it via PHP (if you are printing issued/generated files), your probably thinking "oh, well I can't put HTML in the PDF to execute the javascript". You don't need to! To solve the issue of printing the correct page, here's how:
Insert the following into an HTML/PHP page that the user is sent to (for this solution, the user does not need to visit the .pdf), in the <head> of the landing/success page:
<link rel="alternate" media="print" href="LINK TO PDF FILE">
If you have the above code in your page, when you execute window.print();, it will print the page specified above. If you don't save the PDF locally, you can put it in a temporary directory that is somehow (out of the scope of this question) cleared on a time based or action based schedule, to prevent disk space buildup.
Keep the following in mind:
Kiosk mode doesn't have an exit button. To exit, press ALT + F4.
When printing in kiosk mode, you need both --kiosk AND --kiosk-printing. The printing argument requires the --kiosk argument.
When printing in kiosk mode, it is normal for the print dialog to appear and then suddenly disappear. It can't be prevented without advanced window layering and whatnot.
I'm sure that other browsers have similar functionality to bypass the print dialog, however, I have found that Google Chrome works best in this kind of functionality. If your on a Linux machine, Google has a .deb file that you can install Google Chrome on Linux with, by using the command sudo dpkg -i (package / downloaded .deb file path). Chromium --might-- support this kind of functionality. As far as I know, it should.
If you need additional help, leave your question in the comments below, I'll respond ASAP.
I hope I helped. If I did, feel free to give me a green check to your left. ;)

How can I execute php scripts on Nanohttpd?

Iam new to WebServer and iam using NanoHttpd , Everything work fine and i can connect to my phone using my web browser on my Computer, my problem is that iam trying to run a Php file manager app, called 'fsmanager' , work fine on my website i can browse my files etc, in my index.html i have a simple tag that target fsmanager.php, when i click it, im asked to download the php file, i have tried to add mime type php application/php etc with no luck, source code is same as NanoHttpd,
Any help would be appreciated, Thanks.
Take a look at "Quercus" (http://quercus.caucho.com/) from the folks who make the Resin App-Server. Its a complete implementation of PHP version 5 that runs on the JVM, as a servlet.
While NanoHttpd doesnt support the servlet API specifically, I am sure that you could write hooks to and from Quercus to get something running with NanoHttpd. That would be a fabulous extension to the existing webserver code! :-)
nanohttpd is purely an HTTP server, it will not execute PHP files on it's own.

How do I build a Program that accesses an online script

I want to write a program to contact a PHP script online, and show the HTML output. Basically, it will be a browser that only access the programmed URL.
Similar to Seva's answer but a little better integrated with the Windows GUI. I would put together a simple HTA that used JavaScript to load the required page into an IFRAME. HTA's are executable and provide a simple GUI that is basically IE without all of the controls.
A google search for "Microsoft HTA" should get you going, clearly you already know HTML so putting an HTA together will be easy as it is just HTML and some scripting in either JavaScript or VBscript.
http://technet.microsoft.com/en-us/scriptcenter/dd742317.aspx
You don't need a program. Just execute the URL as a file. In Windows, that'll open the browser. If you need to ship at least something, ship a BAT file with the following contents:
#start http://www.mysite.com/
The builtin start command means "find the right executable for the specified parameter and call it, passing the parameter to it". The default browser is the one registered to handle the http schema.
Or you can ship a URL shortcut. To make one, open the site in IE, and drag from the address bar to the desktop. That'll give you a file with a .URL extension that you can
"execute", either from the shell or from the command line.
It doesn't matter if there is a PHP or Python or anything else on server because scripts give their output in HTML.
What you need is some kind of HTTP-client library like libcurl

Scan folder on local (user's) PC and upload all files(images) to web server

I wish my users could select a directory from their PC and upload all files from this directory, so they could upload whole album(directory) instead of uploading every single file separately.
I would like to ask you if this is somehow possible using PHP or JavaScript and without using any framework.
thank you
First of all, PHP can't do anything to the user's local computer. Since it never runs there (unless the user's computer is the server also).
JavaScript runs on the user's local computer but isn't setup to handle things like this.
Java and Flash runs on the user's computer and can be setup to do exactly this.
Look at SWFUpload. I highly recommend it.
And if you want Java, check out RadUpload. The lite edition is free.
A thing to note, what these Flash and Java solutions both do is accept a file selection from the user and then send that to a PHP script which does the actual uploading.
It would probably make more sense for them to upload a .zip containing multiple images - which is possible in PHP.
I do not think it is possible as you describe it. Create a small utility which they can run on their PC that will do the job. Also check out how Facebook upload image works. They upload dozens of images at the same time.
Not possible using purely php/javascript. However, take a look at http://www.element-it.com/JavaPowUpload.aspx, it is a java-based file uploader that allows you to completely hide the interface, and, if you wish, power the whole interface via javascript. However, it is not free, perhaps not suitable for a personal project.
This may not meet your requirement of Javascript, but if you wish you could build your uploader object as an activex object and use CURL to actually perform the upload or do it as a Java applet.
I had built a Java applet based uploader for a client and I found resources on line and used that as my base for building the uploader.
SWFUpload, as mentioned in one of the answers you received is a good one.

Categories