Forum Moderators: coopster

Message Too Old, No Replies

Trigger PHP action from file in folder

         

Inspector Mills

7:24 am on Jun 16, 2011 (gmt 0)

10+ Year Member



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.

penders

5:58 pm on Jun 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To simulate your 'hotfolder', you could schedule a CRON job on your server to run periodically (every few minutes?!). The CRON job can run your PHP script directly, checking for any XML files and processing accordingly.

To POST your XML data to a url are you using the cURL library?

Inspector Mills

10:14 am on Jun 17, 2011 (gmt 0)

10+ Year Member



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. I will investigate CRON 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!