Is their any way that whenever a user upload file via ftp a function fire automatically.I don't have any code.Search it on internet but not find any solution.
Asked
Active
Viewed 76 times
0
-
Check your ftp server documentation. It has nothing to do with php – zerkms Dec 18 '13 at 23:33
1 Answers
2
There is, and there is not - let me explain: When a user uploads a file via FTP, there are two players, who know about this fact:
- The FTP server software: It might or might not have a hook to notify a consumer
- The OS: It might or might not have such a facility
If you control the whole stack, i.e. OS, FTP-Server and your appliaction, you can quite easily do this, e.g. have inotify
on Linux run a PHP interpreter. Be aware: This is not portable e.g. to some hosting site.
What seems to be a portable and mostly good enough way to do things is a polling loop:
- use e.g. PHP's
flock
facility to synchronize between concurrent requests - have the winning (in the previous step) process update a file with the last change timestamp on the directory in question
- store the last seen such timestamp in your session, and on every request compare it to the current one: If they mismatch, you know at least something happened and can explore further.

Eugen Rieck
- 64,175
- 10
- 70
- 92