Jump to content

Trigger PHP action from file in folder


Inspector Mills

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

You might also want to take a look at incrond, it is different to normal cron in that it executes script when certain filesystem events occur (ie; a file is created within a certain directory), not like normal cron which just executes scheduled tasks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.