473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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.php', 'index.php');
}

TIA

jg

Aug 14 '06 #1
2 1590
Rik
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.php', '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
Aug 14 '06 #2
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.php', '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
Aug 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Joe Laughlin | last post by:
(file and class names changed to protect the innocent) g++ -Wall -c file.cpp: In member function `std::string Some_Class::get_member(const std::string&) const': file.cpp:46: passing `const...
2
by: sarah | last post by:
I keep getting the following error: g++ SortedList.cpp SortedList.cpp:260: error: expected constructor, destructor, or type conversion before '*' token SortedList.cpp:260: error: expected `,' or...
0
by: noureensyed | last post by:
Hi there, 1. I have the following XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="1.0">
4
by: Sahil Malik [MVP] | last post by:
Okay so lets say I have a valuetype - lets say DateTime. Look at this code . List<DateTime> dt = new List<DateTime>() ; dt.Add(new dateTime(1999,12,1)) dt.AddDays(1) ; <--- This statement...
6
by: queisser | last post by:
Hi all, I'm writing a C# app that uses copy/paste to put graphics in a window. My copy/paste logic first looks for Metafile, then for bitmap. Here's the problem: when I copy and paste a WMF...
8
by: XYZ | last post by:
I need to pass the address of a variableto some win32 API functions like RTLMoveMemory I noticed some weird behavior when pinning objects and using the handle's pointer to write data to the...
18
by: atv | last post by:
at least to me it is. I can't figure out for the life what it is i'm doing wrong here. i have a function called assign_coordinate. usually, i pass a malloced pointer to it, then individual...
20
by: ongaro.admin | last post by:
Hi, I'm experiencing a strange problem with .mdb files. We have two buildings connected by optical fiber (a single LAN). Everything works perfect with any file, any size, any application...
4
by: Adam Biser | last post by:
My apologies if this has been discussed before, but using Google and also searching the newsgroup has not given me any insight to this problem. I'm experiencing some strange behavior when I copy...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.