Trigger PHP action from file in folder

Hi there

I have a strange request, and am not sure if it will be possible.

I need to be able to POST XML data to a url, that will be extracted from a document. I have read up a little, and have found that both extracting data from a document, and POSTing to a url is possible in PHP.

However, the problem that I have is this: I do not know how to trigger the PHP action. I am using a hotfolder-based application to generate the XML file, which places the XML document into a specific folder. I need for PHP to act on the file when it arrives in that folder, and automatically POST the data to the necessary url. In a sense, I need the folder into which the XML files are being saved, to be some kind of “hotfolder” which will be polled or “watched” by an application, and kick into action once a file arrives in that folder.

The reason I mention that I am using a hotfolder-based application, is that it is possible that I create a custom hotfolder which will trigger a batch file when a file arrives in the folder that is being watched. I can make this batch file to do whatever I need to. In other words, a possible solution would be to have a batch file trigger the PHP action. Again, I do not know if this possible with a batch file, or how do do it if it is.

Any guidance would be appreciated.

You could have your batch file file request your PHP script over HTTP, this would execute the script on the server and perform the actions stipulated within it.

As you mention a batch file, I assume you’re using a Windows based system?

Thanks for the reply, Anthony.

I am pretty new to PHP, so I am a bit lost. How do I have a batch file “request a PHP script over HTTP”?

Yes, I am on Windows.

Is the PHP script on the same server? If so you can use PHP’s CLI to invoke the script and bypass the remote call altogether.

I have since discovered that I cannot use the batch file in my third-party hotfolder, because I cannot find a way of getting the batch file to read the contents of the specific file (the XML file) that is triggering the batch action. Even if I could, I would need for PHP to read the contents or, more accurately, extract the contents of this file for POSTing. The chances are there are going to be a number of files waiting in this folder, so PHP would need to know which one to look at.

Which takes me back to having a folder “polled” by another application that can trigger the PHP action. Someone suggested CRON - I will investigate this as an option.

Another potential problem comes to mind, though - the file would need to be deleted once the action has been called on, otherwise it would repeat the action indefinitely.

Thanks for your assistance - it is probably quite evident that I am a bit out of my depth here!

That’s a shame. :frowning: