cron??
Moderator: General Moderators
cron??
ok here's the idea...i have a directory in my site where i dump my pdf files, lets call the directory myPDFs...inside the directory, i have one.pdf, two.pdf, three.pdf...now, every week, i need to update and replace the content of that directory, having the same file names, overwriting the previous files...these files will be coming from another directory, lets call it my2ndPDFs...i want it to update automatically instead of uploading every week the updated files....i was thinking of cron, but i am not very familiar with it..and don't really know where to start...is there any function that can do this??with or without the cron??i really don't know cron so i may have the wrong impression...please guide me...thanks in advance... 
By personal experience, I say NEVER rely on cron for anything.
I personally always do my "cron jobs" thru php, using time() or date(), so like in your index.php (which I assume would be the page most visited on your site) just make a check if 1 week has passed since your last "updated" and if it has just run the php script to do the things you wanna do.
I personally always do my "cron jobs" thru php, using time() or date(), so like in your index.php (which I assume would be the page most visited on your site) just make a check if 1 week has passed since your last "updated" and if it has just run the php script to do the things you wanna do.
well personally for all of my sites I have a config table with 2 fields <name> <value> in which I store all the "1 time" information related to the site.
So for your case you could have like:
lastupdate -> time of last update
so lets say you update now and store time().
in your index you can do this:
then you know that in 1 week heres 604800 seconds, so:
So for your case you could have like:
lastupdate -> time of last update
so lets say you update now and store time().
in your index you can do this:
Code: Select all
$lastupdate = mysql_result(mysql_query("SELECT value FROM config WHERE name='lastupdate'"),0);Code: Select all
$timenow = time();
if($lastupdate - $timenow > 604800) //more than 1 week passed
{
//do your stuff here
//and update the database
mysql_query("UDPATE config SET value='$timenow' WHERE name='lastupdate'");
}I use cron all the time to get stuff done - it works great if you set it up properly. For something like this, I'd make a PHP script that moves all the PDFs from my2ndPDFs to myPDFs
Set the permissions so that it's executable, then toss it in your cron.weekly directory. Done.
Code: Select all
$from_path = '/var/www/mypdfs';
$to_path = '/var/www/my2ndpdfs';
chdir($from_path);
$files = glob('*.pdf');
foreach($files as $filename)
{
rename($from_path.'/'.$filename,$to_path.'/'.$filename);
}Real programmers don't comment their code. If it was hard to write, it should be hard to understand.