RecentUpload: Difference between revisions
(Initial Version) |
SaratogaWX (talk | contribs) m (Text replacement - "http://sandaysoft.com/forum/" to "https://cumulus.hosiene.co.uk/") |
||
(18 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{AddOnBanner|name=RecentUpload|type=HTML & PHP|author=Jason Duncombe|contact=6719jason via Forum|updated= |
{{AddOnBanner|name=RecentUpload|type=HTML & PHP|author=Jason Duncombe|contact=6719jason via Forum|updated=23rd Aug 2009|version=1.3}} |
||
<big>RecentUpload</big> shows a list of files on your webserver and the date and time of their last update. This is predominately useful for a system admin/website owner as a quick and convenient way to check that Cumulus has been able to upload the necessary data files and webpages to your site. It is not specific to Cumulus files so you could check other files on your webserver! |
<big>RecentUpload</big> shows a list of files on your webserver and the date and time of their last update. This is predominately useful for a system admin/website owner as a quick and convenient way to check that Cumulus has been able to upload the necessary data files and webpages to your site. It is not specific to Cumulus files so you could check other files on your webserver! |
||
Unlike usual file "sniffers", this will tell you when a declared file is missing (eg. a file has been deleted but new upload has failed) |
|||
Line 17: | Line 19: | ||
//config - define variables to match the files you are interested in |
//config - define variables to match the files you are interested in |
||
// format: "file nickname", "update frequency", "file url" |
// format: "file nickname", "update frequency", "file url" |
||
// - nickname may be "" (will be replaced by url) |
|||
// - freq may be "" (will be replaced by 'Unknown') |
|||
⚫ | |||
// - file url - valid filepath - COMPULSORY |
|||
⚫ | |||
$nickname[] = " |
$nickname[] = "'Realtime.txt"; $freq[]="30 Seconds"; $file_url[]="./realtime.txt"; |
||
$nickname[] = " |
$nickname[] = "Homepage"; $freq[]="2mins"; $file_url[]=".index.html"; |
||
⚫ | |||
⚫ | |||
$nickname[] = "Today's Data Review"; $freq[]="2mins"; $file_url[]="./today.html"; |
|||
$nickname[] = "Yesterday's Data Review"; $freq[]="2mins"; $file_url[]="./yesterday.html"; |
|||
// ######### That's it, nothing else to do ! |
// ######### That's it, nothing else to do ! |
||
Line 34: | Line 39: | ||
if(file_exists($file_url[$i])) { // cheap and cheerful existence check |
if(file_exists($file_url[$i])) { // cheap and cheerful existence check |
||
$when=filemtime($file_url[$i]); |
$when=filemtime($file_url[$i]); |
||
$this_output .= "<tr><td>" .($nickname[$i] ? $nickname[$i] : $file_url[$i]). "</td><td>" .$freq[$i]. "<td>" .date("m/d/y H:i:s T", $when). "</td><td>" .timediff($file_url[$i]). "</td></tr>\n"; |
$this_output .= "<tr><td>" .($nickname[$i] ? $nickname[$i] : $file_url[$i]). "</td><td>" .($freq[$i] ? $freq[$i] : "Unknown"). "<td>" .date("m/d/y H:i:s T", $when). "</td><td>" .timediff($file_url[$i]). "</td></tr>\n"; |
||
} else { // the file is misnamed or not uploaded |
} else { // the file is misnamed or not uploaded |
||
$this_output .= "<tr><td>" .$file_url[$i]. "</td><td>" .$freq[$i]. "<td |
$this_output .= "<tr><td>" .$file_url[$i]. "</td><td>" .($freq[$i] ? $freq[$i] : "Unknown"). "<td>NO SUCH FILE !</td><td>NO SUCH FILE !</td></tr>\n"; |
||
} // END existence check |
} // END existence check |
||
} // END array loop |
} // END array loop |
||
Line 88: | Line 93: | ||
?> |
?> |
||
</pre> |
</pre> |
||
=Configuration= |
=Configuration= |
||
Line 97: | Line 101: | ||
{| class="wikitable" border="1" |
{| class="wikitable" border="1" |
||
|- |
|- |
||
!style="width: |
!style="width:90px" | Variable |
||
!style="width:400px" | Description |
!style="width:400px" | Description |
||
!style="width:150px" | Example |
!style="width:150px" | Example |
||
Line 103: | Line 107: | ||
|$nickname[] |
|$nickname[] |
||
|Describe the use of the file. If you leave this blank it will use the filename as the description |
|Describe the use of the file. If you leave this blank it will use the filename as the description |
||
|Realtime data |
|"My Realtime data" |
||
OR "" |
|||
|- |
|- |
||
|$freq[] |
|$freq[] |
||
|How often would you expect the file to be updated. This is for your information only and is displayed on the page but does not have any affect on the code |
|How often would you expect the file to be updated. This is for your information only and is displayed on the page but does not have any affect on the code, "" = "Unknown" |
||
|15 seconds |
|"15 seconds" |
||
OR "" |
|||
|- |
|- |
||
|$file_url[] |
|$file_url[] |
||
|the path to where the file is, relative to where this code is running |
|the path to where the file is, relative to where this code is running ('''REQUIRED''') |
||
|./realtime.txt |
|"./realtime.txt" |
||
OR "realtime.txt" |
|||
|} |
|} |
||
A complete set of three variables is required for each file to be checked. Repeat as necessary; in the above example we are checking four files. |
A complete set of three variables is required for each file to be checked. Repeat as necessary; in the above example we are checking four files. |
||
=Testing= |
=Testing= |
||
Line 144: | Line 150: | ||
function file_data(phpurl) { |
function file_data(phpurl) { |
||
if (document.getElementById) { |
if (document.getElementById) { |
||
var xx = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); |
var xx = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(phpurl); |
||
} |
} |
||
if (xx) { // got something back |
if (xx) { // got something back |
||
Line 150: | Line 156: | ||
try { if (xx.readyState == 4 && xx.status == 200) { |
try { if (xx.readyState == 4 && xx.status == 200) { |
||
⚫ | |||
// var currdat = x.responseText.replace(/\r\n/g, ""); // this gets rid of any line ending |
|||
// var currdat = currdat.split(' '); // populate the array |
|||
⚫ | |||
} // END if (xx.readyState == 4 && x.status == 200) |
} // END if (xx.readyState == 4 && x.status == 200) |
||
Line 166: | Line 169: | ||
setTimeout("file_data(phpdatFile + '?' + new Date().getTime())", 1000); // get new data |
setTimeout("file_data(phpdatFile + '?' + new Date().getTime())", 1000); // get new data |
||
// } |
|||
} |
} |
||
} // end file_data function |
} // end file_data function |
||
Line 185: | Line 187: | ||
Your page will now refresh the data every one second. |
Your page will now refresh the data every one second. |
||
To change the refresh rate adjust the figure 1000 in the code above. This is the time in milliseconds. So to refresh every 30 seconds it would be 30000 |
To change the refresh rate adjust the figure 1000 in the setTimeout(" ... code above. This is the time in milliseconds. So to refresh every 30 seconds it would be 30000 |
||
⚫ | |||
[http://www.weeleyweather.co.uk/index.php?page=serverstatus Server Status] |
|||
=Download Location= |
|||
You can download the latest and previous versions, directly from the forum [https://cumulus.hosiene.co.uk/viewtopic.php?f=14&t=1257&start=0 Sandaysoft Cumulus Forum] |
|||
⚫ | |||
http://www.weeleyweatherstation.info/betel_ftpstatus.php |
|||
[[Category: |
[[Category:WebTools]] |
Latest revision as of 15:45, 2 November 2018
Name: | RecentUpload |
Type: | HTML & PHP |
Author: | Jason Duncombe |
Contact: | 6719jason via Forum |
Last update: | 23rd Aug 2009 |
Version: | 1.3 |
RecentUpload shows a list of files on your webserver and the date and time of their last update. This is predominately useful for a system admin/website owner as a quick and convenient way to check that Cumulus has been able to upload the necessary data files and webpages to your site. It is not specific to Cumulus files so you could check other files on your webserver!
Unlike usual file "sniffers", this will tell you when a declared file is missing (eg. a file has been deleted but new upload has failed)
This script relies on PHP so your webserver must support it (The majority of hosted servers do. If you are running your own webserver you many need to install and configure it)
Installation
Copy the following code into an existing web page, or create a new page. All this code should appear within the <body> </body> tags.
As this is PHP code, the webpage filename must ended in ".php". For example, recentupdate.php
<?php //config - define variables to match the files you are interested in // format: "file nickname", "update frequency", "file url" // - nickname may be "" (will be replaced by url) // - freq may be "" (will be replaced by 'Unknown') // - file url - valid filepath - COMPULSORY $nickname[] = "'Realtime.txt"; $freq[]="30 Seconds"; $file_url[]="./realtime.txt"; $nickname[] = "Homepage"; $freq[]="2mins"; $file_url[]=".index.html"; $nickname[] = "Station Records"; $freq[]="2mins"; $file_url[]="./record.html"; $nickname[] = "Station Trends"; $freq[]="2mins"; $file_url[]="./trends.html"; $nickname[] = "Today's Data Review"; $freq[]="2mins"; $file_url[]="./today.html"; $nickname[] = "Yesterday's Data Review"; $freq[]="2mins"; $file_url[]="./yesterday.html"; // ######### That's it, nothing else to do ! $this_output = " The current data and time is: ".date("m/d/y H:i:s T")."<br/><br/> <table> <tr><th>Uploaded File</th><th>Upload Frequency</th><th>Last Upload</th><th>Time Since Last Upload</th>"; for ($i=0; ($i<count($file_url)); $i++) { if(file_exists($file_url[$i])) { // cheap and cheerful existence check $when=filemtime($file_url[$i]); $this_output .= "<tr><td>" .($nickname[$i] ? $nickname[$i] : $file_url[$i]). "</td><td>" .($freq[$i] ? $freq[$i] : "Unknown"). "<td>" .date("m/d/y H:i:s T", $when). "</td><td>" .timediff($file_url[$i]). "</td></tr>\n"; } else { // the file is misnamed or not uploaded $this_output .= "<tr><td>" .$file_url[$i]. "</td><td>" .($freq[$i] ? $freq[$i] : "Unknown"). "<td>NO SUCH FILE !</td><td>NO SUCH FILE !</td></tr>\n"; } // END existence check } // END array loop $this_output .= "</table>\n"; echo $this_output; //========================================================================== // Function timediff - Jason Duncombe - Weeley Weather Station UK // // version: 1.2 - 19/08/09 - Public Released version // Description: This function calculates the number of seconds, minutes, // hours, or days since the file's timestamp has been written. This works // well for files uploaded to your website via FTP, since the timestamp // reflects when the file was last written to the server with your FTP client. //========================================================================== function timediff ($filepath) { //Get time stamp of file $t = date("mdyHis", filemtime($filepath)); //Split $t into month, day, and year values $m = substr($t, 0, 2); $d = substr($t, 2, 2); $y = substr($t, 4, 2); $h = substr($t, 6, 2); $min = substr($t, 8, 2); $s = substr($t, 10, 2); $timestamp = mktime($h, $min, $s, $m, $d, $y); $tdiff = mktime() - $timestamp; //Subtrack $timestamp from now, give us diff in seconds. //Determin how to display by size of timediff if ($tdiff < 60) { //Timediff is less then 1 minute, so must be seconds $tdiff=number_format($tdiff); return $tdiff." sec"; } elseif ($tdiff < 3600) { //timediff is less then 1 hour, so must be minutes $tdiff=$tdiff/60; $tdiff=number_format($tdiff, 1, '.', ''); return $tdiff." min"; } elseif ($tdiff < 216000) { //timediff is less then 1 day, so must be hours. $tdiff=($tdiff/60)/60; $tdiff=number_format($tdiff, 1, '.', ''); return $tdiff." hr"; } else { //timediff is greater then 1 day, so must be days. $tdiff=(($tdiff/60)/60)/24; $tdiff=number_format($tdiff, 1, '.', ''); return $tdiff." days"; } } ?>
Configuration
At the top of this code are a set of variables, three for each file to be checked:
Variable | Description | Example |
---|---|---|
$nickname[] | Describe the use of the file. If you leave this blank it will use the filename as the description | "My Realtime data"
OR "" |
$freq[] | How often would you expect the file to be updated. This is for your information only and is displayed on the page but does not have any affect on the code, "" = "Unknown" | "15 seconds"
OR "" |
$file_url[] | the path to where the file is, relative to where this code is running (REQUIRED) | "./realtime.txt"
OR "realtime.txt" |
A complete set of three variables is required for each file to be checked. Repeat as necessary; in the above example we are checking four files.
Testing
Save the file (remember the .php at the end) and upload to your webserver. Now surf to the page using your website address and location of the php file. Example www.myserver.com/recentupload.php. If all goes well you should see a table with your filenames and when they were last updated.
Tip
Rather than add all this code to your existing page, create a new file with all the code, save it (let's call it recentupload.php). Now in your actual website page, insert the following line
<?PHP include("recentupload.php");?>
Note: your 'actual' website page must now also have .php at the end of the filename and not .html for this to work.
Further Enhancement
Why not have the page refresh automatically? (This works for either html or php file types)
Somewhere in the <head> tag (or if you wish in the <body>) place the following code:
<script language="javascript"> var phpdatFile = 'recentupload.php'; // URL location of PHP file function file_data(phpurl) { if (document.getElementById) { var xx = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(phpurl); } if (xx) { // got something back xx.onreadystatechange = function() { try { if (xx.readyState == 4 && xx.status == 200) { document.getElementById('the_content').innerHTML=xx.responseText; } // END if (xx.readyState == 4 && x.status == 200) } // END try catch(e){} // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE } // END xx.onreadystatechange = function() { xx.open("GET", phpurl, true); xx.send(null); setTimeout("file_data(phpdatFile + '?' + new Date().getTime())", 1000); // get new data } } // end file_data function // initial call file_data(phpdatFile + '?' + new Date().getTime()); </script>
Update the top of this code....var phpdatFile = 'recentupload.php'; with the filename you used earlier (in the Tips section above).
Now, somewhere in the <body> of your html page insert the line
<div id="the_content">Any Second Now......</div>
Your page will now refresh the data every one second.
To change the refresh rate adjust the figure 1000 in the setTimeout(" ... code above. This is the time in milliseconds. So to refresh every 30 seconds it would be 30000
Example
Download Location
You can download the latest and previous versions, directly from the forum Sandaysoft Cumulus Forum