Jump to content
Larry Ullman's Book Forums

C++ with PHP - Possible?


Recommended Posts

Hi Larry,

Is it possible to have a Windows Form in C++ 'communicate' with a PHP back-end with all functionality being on one PC?  I.e., the implementation of PHP in my case would be via XAMPP.

Specifically I'd like to have a C++ Windows Form as that has access to the PC file system, and then pass some data from the PC file system to a PHP back-end which would do some work on the file passed to it.  Once the work was done then some communication back to the Windows Form front-end to say that the work had been done.

I did something like this a few years ago with Adobe AIR as the front-end and PHP as the back end, but would now like to do something similar but with the Windows Form C++ as the font-end.

Looking forward to your advice.

Cheers from Oz.

Link to comment
Share on other sites

I imagine it _may_ be possible but it's the kind of situation where I feel like the answer is "this is probably not what you should be doing". In that it feels like you're only using PHP here because you're most comfortable with it. If you're starting with C++, my inclination would be to try to do all the work in C++. But let me know if I'm missing something.

Link to comment
Share on other sites

Hi Larry,

I want the front end to be C++ so that I have access to the PC file system.  Apparently it can be done with cpprestsdk and I will check it out.  I wonder if I could do it the other way around with PHP on the server calling a C++ module on my PC to get access to the PC file system?  I want to access a directory on the PC which, apparently cannot be done with PHP or an HTML form.  I want the full path of the directory, not an upload.

Re being comfortable with PHP - yes you are right on that count but I'm learning a lot more of C++ particularly using Visual Studio as the IDE which has nice PC forms functionality.

Thanks for your reply.

Cheers

Link to comment
Share on other sites

Hi Larry,

FYI I installed cpprestsdk and associated it with Visual Studio 2019 and yes, a test C++ program successfully called and received a response from an external website.

BUT (isn't there often a BUT) when I tried to integrate the code that uses cpprestsdk into a Windows form application, I found out that they are incompatible!

Well, it was an interesting learning exercise :-)

As an aside, I found it quite tricky to install cpprestsdk but carefully following guidance courtesy Dr Google I eventually managed to get it installed and working with VS2019 (but not VS2017) in a Windows 10 PC.

Thanks for your interest.

Edited by Necuima
Added some more information
Link to comment
Share on other sites

Thanks for the update. I'm still a bit confused by the scenario. If PHP is running on the same Windows machine as the files, then it should be able to access the full path. If not in the web version of PHP (presumably due to permissions), then the command-line PHP can. Apologies if I'm missing something.

Link to comment
Share on other sites

Hi Larry,

I am missing something.  I select a file or a directory on my PC in a PHP script which includes an HTML form and within the form I use upload.  Then on the redux pass I can move that file to a server location and do some stuff with it.  No problem.  But what I want to do is do some stuff to the file on the PC which I can do if I know the full path of the selected file.  And in a slightly different PHP script I want to select a directory on my PC and get its full path so that I can then iterate over the files therein and do stuff to them.

What am I missing? And thank you as always.

Cheers

P.S., using a C++ front end or a Flash front-end program I can get the full path names of files and directories on my PC.  Then, at least the Flash case, I can pass those data to a PHP back-end which nicely does what I want it to do for those selected files on my PC.  I do not want this functionality for files on an external web-server.

Edited by Necuima
Added more information
Link to comment
Share on other sites

Ah, okay. Thanks for explaining! I guess my inclination in this case would be to make a command-line utility that does the work you want to do and you provide this utility with the path to a file when you invoke it. The main issue in my mind is that "uploading" a file from a computer to itself is a marker of making a process more complicated than it needs to be. 

You could also write the command-line utility to accept a directory as an argument and then iterate through that directory. 

Let me know if this is still unclear. 

Link to comment
Share on other sites

Hi Larry,

Thanks as always for your interest and advice.

As an aside I had not used FLEX/WindowedApplication for a few years so I was a bit rusty but all OK again now.  Referred to your FLEX and AIR books both of which I have.  I now have the application working just fine on both Win7/PHP 5.6 and on a separate computer with Win 10 and PHP 7.1

Cheers from Oz, Necuima

Link to comment
Share on other sites

  • 1 month later...

Hi Larry,  back in April I was looking for a way for a C++ front-end to 'communicate' with a PHP back-end with all functionality being on one PC?  I.e., the implementation of PHP in my case would be via XAMPP.

On April 21st I reported that I had tried to use cpprestsdk (Casablanca) with a Windows Form via Visual Studio but that did not work.

But today I managed to get the functionality to work perfectly by developing the form with Microsoft Foundation Classes (MFC) which I had never used before :-)  That took over 2 months - just as well that I am retired and have the time (and perseverance :-)  The IDE was VS2015/19 Community Editions.

Just FYI, Cheers

 

Link to comment
Share on other sites

The MFC form does not use .NET whereas the VS2015/19 standard form constructs use .NET and that was what was preventing the cpprestsdk (Casablanca) communication with the back-end server on localhost. At least that is how I understand it.

Again, just FYI.

Cheers

Link to comment
Share on other sites

 Share

×
×
  • Create New...