Page 1 of 1
Trigger a php file to run during an FTP upate of file?
Posted: Fri Dec 02, 2011 3:59 pm
by jellis00
Is there any way to trigger a php file to execute by a FTP? I periodically FTP file updates to the website and would like the php script that is in the same folder as the file to execute after each new file is updated by the FTP. This way, the php script updates my database with the new file contents as a result of each FTP.
I send these FTP file updates hourly and would like all of them to end up in the database so the next login to the webpage by a user will see the current results that were previously posted to the database via the FTP updates. Without this some of the FTP file updates don't get into the database.
Would appreciate anyone's advice as to how I might do this.
Re: Trigger a php file to run during an FTP upate of file?
Posted: Fri Dec 02, 2011 4:55 pm
by califdon
I would suggest that you consider a different approach. I have a couple of sites where files are uploaded from time to time to one of several directories, for viewing by members. In the PHP scripts that display the web pages, I use the PHP opendir() function to read the filenames in the appropriate directory, then format them for display and generate the links to permit the user to select and view them. This way, whatever is contained in the directory is what determines what is shown at all times and there is no need to update the scripts. My method depends on creating a directory dedicated to these contents and in my case, I manage the filenames so that they always can be formatted to neat display names. That managing is done in the script that uploads them. Here is a snippet from the code that displays them:
Code: Select all
<?php
$dir = opendir('WSarchives/') or die("Can't open WSarchives directory");
$fnarray = Array();
while( false != ($fn = (readdir($dir)))) {
if($fn != '.' && $fn != '..' && preg_match('/^WS/',$fn)) {
$fnarray[] = $fn;
}
}
closedir($dir);
rsort($fnarray);
foreach($fnarray as $fn) {
// format filename date:
$yr = substr($fn,2,4);
$mo = (int) substr($fn,7,2);
$dt = mktime(0,0,0,$mo,1,2009);
$mo = date('F',$dt);
echo "<tr height='32'><td width='8' style=\"background-image: ";
echo "url('vert2.gif')\"></td><td colspan='2'> </td>";
echo "<td style='text-align:center;'>";
echo "<a href='WSarchives/$fn'>$mo $yr";
echo "</td><td colspan='2'> </td>";
echo "</td><td width='8' style=\"background-image: url('vert2.gif')\"></td></tr>";
$pos++;
}
?>
If you want to see the results, visit
http://norcaltos.org/windsheetarchives.php.
Re: Trigger a php file to run during an FTP upate of file?
Posted: Fri Dec 02, 2011 7:16 pm
by jellis00
I see what you are suggesting. However, your approach doesn't use a database and I believe I have to use a database as opposed to reading data from a directory of files and populating them in an array for following reasons.. I use the databse as the repository for hourly data updates that are sent to the website as a rewrite of a single word in a file. Each hourly update is checked for the time of the update and is then stored in the database in a field that is equivalent for that hour. For example, one of the files updated by FTP is hour.txt containing 00, 01, 02, et for each hour of a 24 hour day. Other files contain single word data that pertains to that fields value at that hourly time. My php code tests for the hour of the data and then shoves all the other data items into their respective fields.
As you can see, I don't have files for every hour....I use one set of files that I dynamically change every hour and then read that hours contents into the database. To use your approach I would have to have 24 sets of data files and a very complicated FTP routine on the sending end...or am I misunderstanding your approach?
My problem is how to get the hourly updated data that ends up in the one set of files into the database so that the next userlogin will see all of the previously FTP'd hourly updates...not just one update.
I don't see how I could do this by your approach, which as I understand it only reads the directory into an array when a user logsin and triggers the php file to read the directory and populate the array. I had to create a database of 24 fields to cover the 24 hour period of a day, with each field indicator being 0hour, 1hour, 2hour, ...,23hour, where nhour is acronym for time 00:00,01:00,02:00, etc. If I could show a record format for the database here it would be easier to understand. Here is a try as a text line that shows the field indicators (parsed by comma) of the database table that is used for records:
loginName (primary), chipID, 0hour,1hour,2hour,3hour,4hour, etc, etc.
Don't see how I could index the hourly data with your readdir approach into an array (which is volatile after the current login) nor how I could prevent loss of the FTP'd data in between logins. Any suggestions?