How to create a shortcut in php? - php

Is it possible to create a shortcut that points to in-existing file in php and make it run normally in windows?
Example
makeshortcut("C:\Windows\calc.exe","short.lnk");
Then when I download the shortcut, it would open calc on my computer.
I don't have COM enabled, I do have exec() enabled, so I can run some kind of perl or python, however, lots of extensions are disabled, particlarly (pywin32 and win32::shortcut), so it would be highly appreciated if I can do this only in php or using calling another script with exec() which doesn't require me to install additional extensions.

The linux ln command has nothing to do with Windows .lnk files, and they are not compatible.
Here is some info on the .lnk file format.
As you can see it is not trivial to create from scratch.
liblnk library allows you to read .lnk files in Linux, but I haven't seen one that allows for their creation.
Edit:
Here is a SO question similar to yours:
Generate Windows .lnk file with PHP and Creating a Desktop Shortcut Using a Web Page

You can use http://www.mamachine.org/mslink/index.en.html - a bash and c program to create a shortcut.
Compile the C program for your platform and call it with the shell_exec function.
Even if the question is old, I hope it helps others.

Related

PHP formatting in VSCode on remote Workspace without using Composer

My Setup: Ubuntu 20 with PHP and Composer
My Editor: VSCode with SSH FS extension to access remote workspace.
My Task: do some PHP stuff, mainly Wordpress Themes
My Problem: no PHP Formatter extension works on the remote Workspace
I tried to use: PHP-CS-fixer, Prettier with PHP plugin, phpfmt, phpcs, PHP Formatter...
Some of them will even not work on my local Workspace.
I can't install new Code on the remote Server (Composer), so i need a way to format PHP files just out of the Box like HTML or JS.
But meanwhile i think, this is not possible.
Solution: use Ubuntu to connect to the server and mount that folder in workspace, let VSC think it is a real local folder :-)
The problem with most formatting extensions is that they expect the files to be on a local drive, as in being mounted outside VS Code, including network shares by any NodeJS program (and therefore VS Code extensions). The extension uses the extension API's FileSystemProvider to provide FS access to VS Code. It is only recently that they added a way for one extension to use file systems provided by other extensions, and it's even more recent that they started pushing extensions to make use of this.
Sadly enough, not every extension developer might start using it, and it's especially tricky for extension that use native/external programs. That includes most language-servers and formatters.
For your use case, there are two solutions though:
Mount the folder on the OS level (e.g. sshfs) and just open it as a regular directory in VS Code, as another answer suggested
Use VS Code's Remote SSH, which actually runs the extensions on the server, therefore skipping the whole "files aren't on a local drive" problem

Run a C++ Application on a Webserver with WordPress

I have a C++-library (.so) for some calculations that I would like to call from Wordpress/PHP via an input formular. The promising idea to build the .so-library as a PHP extension using PHP-CPP has been fine locally on Ubuntu 14.04. But on the webserver this method failed because my webhoster doesn't support changing the extension directive in the php.ini/.user.ini. I see the following alternatives:
Build an exutable application and run it from PHP via proc_open() and send a lot of variables to the stdin of the application. Wordpress itself offers PHP plugins.
Redirect to another server where my own php extensions are supported.
Is there a way using python/web2py for that purpose?
Which would be best?
Or any other ideas?
Probably the simplest way is to create command line utility in C++ and execute it from php with shell_exec. I tried that in past and the performance was not too bad.
"Probably the simplest way is to create command line utility in C++ and execute it from php with shell_exec. I tried that in past and the performance was not too bad."
This did help. Finally I managed a build on Linux which was portable to the webserver where the website and wordpress are located. The call to the binary built from C++ was done with shell exec or popen in PHP (which one I don't remember, it was in 2018). The PHP code was finally migrated to an own wordpress plugin. Unforunately, I could not use PHP-CPP due to missing admin rights for the webderver. But the integration via shell exec or popen works fine.

How can I to run php script from powershell-commandline?

How can i setup my powershell to run php scripts in like a commandcall like this
php test.php
I'm able to do this on a server at work which I connect to by putty, but would be nice if I was able to execute those scripts directly from my own without having some server running.
I also know about Xaml, which I don't like since its require you to refresh some browser.
You can do all the stuff suggested above or ...
Go to php.net and download the php file stack for windows.
Copy the file stack into say c:\php or if you want multiple versions, say c:\php5 or c:\php7 etc.
Open powershell and type c:\php\php.exe -h, you will get the php help output. Yay you are up and running, whoot.
(Note: you may need to rename php.ini.development -> php.ini
Advanced instructions:-
Type env into os search (cortana) and select environmental variables.
Add your php location to path (c:\php) and create a variable php (or php5 etc) pointing to c:\php\php.exe
Now you can run php in powershell with php (php -h to test).
Note: while not the question, this also works in the git bash shell.
I'm assuming windows since you said powershell. You can just install php on windows but that means also installing apache or enabling IIS.
Or there's apparently a built-in webserver for command-line functionality that might minimize the amount of headache involved in configuring that stuff.
This might help get you going also:
http://php.net/manual/en/install.windows.legacy.index.php#install.windows.legacy.commandline

Installing PDFTK on a shared web server

My web sites are hosted on Total Choice Hosting using some kind of Linux (I don't know what precise variety) and Apache. I don't have command line access - I can run command line programs only via exec() in PHP, or via CRON jobs.
Can I install and use PDFTK on a system like this?
If so, what exactly do I have to do? Which files do I have to copy where? Do I have to rebuild PDFTK from source, or is there an executable version somewhere?
Since (as I understand it) PDFTK is based on iText, which is written in Java. Maybe I'd be better off using the original iText package?
Or is there a better way of doing what I want to do (which is basically to merge and flatten a PDF file (blank form) with a FDF file (field values) into a new PDF file (the completed form) and download it to the user)? Is there some native PHP or Python or Perl code to do this?
Thanks - Rowan
A quick glance reveals that the PDFTK source is C++ and it looks like they use GCJ to compile some 3rd party Java code to native code. If you find a pre-built version of PDFTK that matches your OS and architecture you should be able to just upload the binary to your system and run it from PHP using exec. There are some builds available on the install page.
There are some native PHP libraries available for creating and manipulating PDFs. Check out TCPDF, Zend_Pdf, and FPDF to see if any of those are usable. Each one should support what you want to do, its just a matter of choosing the right solution.
Using PDFTK may be the fastest option since it is compiled code, but it is the least portable option since it would require the server have that software installed on it, where the PHP solutions could be distributed with your code.
If you are on a shared host you cant install PDFtk because you don't have access to root to install anything. You need to have a host that has it preinstalled. I use bluehost.com but there up-time is not the best. It works for now but I am going to move to another host once my site is complete. I have had several outages that have lasted for over a day.

Compile a PHP script in Linux

I know PHP scripts don't actually compile until they are run. However, say I want to create a small simple program and compile it to a binary without requiring the PHP binary. How could I do this?
I've seen a few IDE's out there that would do this, but either they are all for windows or the Linux versions don't actually build properly.
What I would like is something like py2exe that does it in the script itself.
Check out phc: the PHP compiler
If you just want to run it like a script, you may not need to compile it per se, but just run it via the command line. Read running PHP via the command line.
There is this: http://www.bambalam.se/bamcompile/ but that compiles to Windows bytecode. There are a few others, but all I have seen will compile for windows only.Few More:
http://www.nusphere.com/products/phpdock.htm
Edit: I almost forgot if your looking to make it work on linux without regard for windows you can just add
#!/usr/bin/php
to the top of the script and you should be able to run it from the command line. Don't forget to chmod +x the file first.
Have a look at Facebook's Hiphop-PHP. It's able to convert PHP code into C++ then compile it with g++. Apparently, they've even gotten it to successfully compile entire WordPress installations.

Categories