Weird Probelms With copy()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jerrygarciuh

    Weird Probelms With copy()

    Hi all,

    The following script is giving me weird problems. I have in this
    directory an index.php and hurricane.php.

    If the script gets $i = 'on' it is supposed to back up the current
    index into a file called normal.php and then copy hurricane.php into
    index.php. This should create a backup of the index and then put the
    hurrican alert in place.

    When the script gets $i = 'off' it should replace the index with the
    contents of normail.php.

    What is happening is that at the end of running with $i = 'on' both
    index.php and normal.php have the contents of hurricane.php.

    Can anyone see why? copy() is returning a 1 every time.

    if ($_GET['i'] == 'on') {
    $result = copy('index.php ', 'normal.php');
    if ($result == 1) {
    $result .= copy('hurricane .php', 'index.php');
    } else {
    $result = 'File Copy Failed!';
    }
    } else if ($_GET['i'] == 'off') {
    $result = copy('normal.ph p', 'index.php');
    }

    TIA

    jg

  • Rik

    #2
    Re: Weird Probelms With copy()

    jerrygarciuh wrote:
    Hi all,
    >
    The following script is giving me weird problems. I have in this
    directory an index.php and hurricane.php.
    >
    If the script gets $i = 'on' it is supposed to back up the current
    index into a file called normal.php and then copy hurricane.php into
    index.php. This should create a backup of the index and then put the
    hurrican alert in place.
    >
    When the script gets $i = 'off' it should replace the index with the
    contents of normail.php.
    >
    What is happening is that at the end of running with $i = 'on' both
    index.php and normal.php have the contents of hurricane.php.
    >
    Can anyone see why? copy() is returning a 1 every time.
    >
    if ($_GET['i'] == 'on') {
    $result = copy('index.php ', 'normal.php');
    if ($result == 1) {
    $result .= copy('hurricane .php', 'index.php');
    } else {
    $result = 'File Copy Failed!';
    }
    } else if ($_GET['i'] == 'off') {
    $result = copy('normal.ph p', 'index.php');
    }
    You do realize that after 2 pageviews all three files will contain the
    content of the chosen condition?

    I'd think this is an unusually complicated manner to get the desired result.

    why not create an index.php, consisting only of:
    <?php
    if(!isset($_GET['i']) || $_GET['i']=='off'){
    include('./normal.php');
    } else {
    include('./hurricane.php') ;
    }
    ?>

    Possibly getting your value for hurricane on/off from a database, an
    ini-file, etc...

    Grtz,
    --
    Rik Wasmus

    Comment

    • jerrygarciuh

      #3
      Re: Weird Probelms With copy()

      Hi Rik,

      Thanks for the reply! My problem is that the index file of the site
      must be backed up and then replaced by a non-technical person with only
      browser access to the site. What I could do is have my script write to
      a text file a 1 or 0 and use an index like you describe but rather than
      it depending on a query string it could look at my text file.

      Thanks for the thoughts!

      JG

      Rik wrote:
      jerrygarciuh wrote:
      Hi all,

      The following script is giving me weird problems. I have in this
      directory an index.php and hurricane.php.

      If the script gets $i = 'on' it is supposed to back up the current
      index into a file called normal.php and then copy hurricane.php into
      index.php. This should create a backup of the index and then put the
      hurrican alert in place.

      When the script gets $i = 'off' it should replace the index with the
      contents of normail.php.

      What is happening is that at the end of running with $i = 'on' both
      index.php and normal.php have the contents of hurricane.php.

      Can anyone see why? copy() is returning a 1 every time.

      if ($_GET['i'] == 'on') {
      $result = copy('index.php ', 'normal.php');
      if ($result == 1) {
      $result .= copy('hurricane .php', 'index.php');
      } else {
      $result = 'File Copy Failed!';
      }
      } else if ($_GET['i'] == 'off') {
      $result = copy('normal.ph p', 'index.php');
      }
      >
      You do realize that after 2 pageviews all three files will contain the
      content of the chosen condition?
      >
      I'd think this is an unusually complicated manner to get the desired result.
      >
      why not create an index.php, consisting only of:
      <?php
      if(!isset($_GET['i']) || $_GET['i']=='off'){
      include('./normal.php');
      } else {
      include('./hurricane.php') ;
      }
      ?>
      >
      Possibly getting your value for hurricane on/off from a database, an
      ini-file, etc...
      >
      Grtz,
      --
      Rik Wasmus

      Comment

      Working...