dry18813 2014-11-14 04:38
浏览 50

Cron Job重命名网页

First, let me say that I know nothing about Cron Jobs or PHP files, so please keep my newbie status in mind if you are kind enough to reply - (use small words and speak slowly!)

I am the webmaster for our organization's site, and I am trying to do something which should be simple, yet time consuming: Take the main web page on our site and automatically update it during the Thanksgiving and Christmas Holidays. I have already created the specific web pages that I need, and uploaded them to the GoDaddy server, but I really don't have the time to go in and manually rename the pages as the days approach; I'm told that a Cron Job would be just the thing to use to automatically save the existing page and rename the new page.

Here is specifically what I want to do: 1) The file Index.htm, located in the root directory, gets either saved or renamed so that I can go back to it after the Holidays are over. 2) The file now named /Holiday Pages/happy_thanksgiving.htm gets moved to the root directory on November 25th and renamed index.htm Same thing with the file named merry_christmas.htm on December 24th. 3) GoDaddy has a Cron Job control panel which allows me to run a specific script on a certain day at a certain time, so I don't think the date codes would need to be embedded into the script itself - but I've not a clue what to put in this script - from talking to the folks at GoDaddy, they suggest a PHP script. 4) Within this PHP script, exactly what commands would I need to write (specific examples please - a sample script would be awesome and MOST appreciated! 5) What would the extension on this script need to be? .TXT or .PHP ??

Thanks in advance! Again, please remember that I'm in over my head here - and pardon my ignorance!

-------------------------------------------------------UPDATE 111/15/14 -------------------------------------------------------- Here's what I have tried so far, using some of your suggestions - the numbers 1) 2) etc are trial script numbers which were then called by the GoDaddy's Cron Job Manager.

1) ----------------------------------------------

<?php
$target = "/holiday_pages/happy_thanksgiving.html"; 
$newName = "/holiday_pages/index.htm";
$renameResult = rename($target, $newName);
// Evaluate the value returned from the function if needed
if ($renameResult == true) {
echo $target . " is now named " . $newName;
} else {
 echo "Could not rename that file";
}
?>

2) ------------------------------------------------

rename('/holiday_pages/happy_thanksgiving.html', '/holiday_pages/index.htm');

3) ------------------------------------------------

rename("/holiday_pages/happy_thanksgiving.html", "/home/user/password/holiday_pages/index.htm");

?> 

4) ------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('./HTML/holiday_pages/index.htm','index.htm.bak');
copy('./HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure      if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

}

5) --------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('../HTML/holiday_pages/index.htm','index.htm.bak');
copy('../HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

}

6) --------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('/HTML/holiday_pages/index.htm','index.htm.bak');
copy('/HTML/holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if     this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');

}

7) ---------------------------------------------------

<?php

$date = new DateTime();
$date -> format('Y.m.d');

if ($date == '2014.11.15') {
copy('./holiday_pages/index.htm','index.htm.bak');
copy('./holiday_pages/happy_thanksgiving.html','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!

}
else if ($date == '2014.11.26') {
copy('index.htm.bak','index.htm');
  • 写回答

4条回答 默认 最新

  • doujuncuo9339 2014-11-14 05:05
    关注

    Just create a file and name it, for example holiday_copy.php. Here is the script itself:

    <?php
    
    $date = new DateTime();
    $date -> format('Y.m.d');
    
    if ($date == '2014.11.25') {
        copy('index.htm','index.htm.bak');
        copy('../Holiday Pages/happy_thanksgiving.htm','index.htm'); // you need to make sure if this (../Holiday Pages/) is the right path to your file!
    
    }
    else if ($date == '2014.11.26') {
        copy('index.htm.bak','index.htm');
    }
    else if ($date == '2014.12.24') {
        copy('index.htm','index.htm.bak');
        copy('../Holiday Pages/merry_christmas.htm','index.htm'); // again, you need to make sure if this (../Holiday Pages/) is the right path to your file!
    }
    else if ($date == '2014.12.27') {
        copy('index.htm.bak','index.htm');
    }
    

    ?>

    you have to run this script on the desired days, best will be at

    0:01 on eg 2014-12-24
    

    You need to place this file in the root directory, where your index.htm is located. If you don't want this, add the appropiate path to all the copied files inside this script - eg here:

    copy('index.htm','index.htm.bak');
    

    Be sure to have the rights to access all the directories and files! Remember to call it on the days after the holiday in order to get your old index.htm back.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line