I have more information about the picture issue. It is not, as I originally thought, that the file is being saved by excel and that it's only blanking for a moment. Instead, there is some sort of corruption in the file and it's blanking until the corrupted file is replaced. The excel file is on a 15 second loop. The next time it loops, it saves over the corrupt file, allowing the page displays correctly. I found this out today when I noticed the page showing a blank box where the picture should have been. I quickly stopped the loop on the excel file before it could save another picture. I was not able to access the picture through a browser even by entering it's direct location in the address bar. I was able to access the file directly on the server's hard drive. It opened up as if nothing was wrong when I accessed it directly on the server, but it still wouldn't load from the browser.
So I still need a better code than what I've got here because this one is also going down the "true" path:
<?php
unlink($filename);
$filename = 'Chart.gif';
if (file_exists($filename)) {
echo '<p align="center"><img border="0" src="Chart.gif" width="932" height="547"></p>';
} else {
echo '<p align="center"><img border="0" src="NoChart.JPG" width="932" height="547"></p>';
}
?>
I tried a few other functions besides file_exists() but everything I tried either came back as always false or always true. I need one that returns "true" when the file can be display and "false" when it cannot.
As for the email script:
$file = "file.html";
$stat = stat($file);
if ( (time() - $stat['mtime']) > 600) { // 600 seconds
// send email ....
}
I have put it on a cron and the email works, but it's emailing me every time the cron runs, so something is wrong with the if() test that is making it say always true. Here's what I'm using now:
<?php
unlink($stat);
$file = "excel.htm";
$stat = stat($file);
if ( (time() - $stat['mtime']) > 600) { // 600 seconds
mail( "***my email address is here****", "Excel is stuck",
"Please exit MS Excel on the web server, then restart it again", "From: ***my email address is here****" );
}
?>
The final issue I need help with is also related to the cron script. I only want it to email me once. If I have the cron running every 5 minutes and the excel file freezes up right after I leave work, I'll have way too many emails by the time I get back in the next morning. Can I the cron script read a text file that either says "running" or "sent" before emailing? If is says "running" the script continues as normal. If the script determines that excel.htm is old, then it overwrites the text file with "sent" after it has emailed me. The next time around it will read the text file and see that it says "sent" and skip the email part. If the cron finds that the file is young again it replaces the text file again with "running"
Anyways, that's my idea. I'm not sure how to implement it. Better ideas are also welcome. I appreciate your help.