PDA

View Full Version : PHP "copy" not working on my Server


largo
04-01-2008, 02:41 PM
Hi, I have a flash movie that sends data to PHP and it writes data to an XML file, when the XML file reaches a certain size then PHP makes a copy of the XML and saves it with a new name. PHP then clears the XML and the whole process begins again.

I´ve tried this on my Wamp test Server and it works perfectly there, but now when I'm trying this on a real server the copy function dosn't work, it just cleans the old XML file when the XML file gets too big. It does not save the old data to a new file ....

Could this have something to do with the users permission on the server???

Can someone help me?:confused:

<?php
$filename = "xmldata/egTest1Data.xml";
$raw_xml = file_get_contents("php://input");
$clean_xml = '<?xml version="1.0"?><Tracks></Tracks>';


print $raw_xml;


//Check File Size. The size returned is in BYTES:-------------
$size = filesize($filename);

//If XML file is larger than 100KB's then make a copy.
if($size > 102400){

//Write normally the last entry:---------------------------
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);

//Copy file with new name containing the day it was copied
$today = date("YmdHi");
$newFile = "xmldata/egTest1Data".$today.".xml";
copy($filename, $newFile);

//Overwrite file to clean XML------------------------------
$fp = fopen($filename, "w");
fwrite($fp, $clean_xml);
fclose($fp);


} else {
//Write normally:------------------------------------------
$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);
}
?>

mojito
04-01-2008, 07:52 PM
Im thinking that the server may be configured differently and you have some undefined variables maybe due to register_globals etc

Check by trying to see these variables exist first, but id recommend another forum for this as its a pure php question, here you have mostly flashers.

jsebrech
04-02-2008, 09:20 AM
Are you certain the account the php process is running as has write access to the folder you want to copy the file to? AFAIK, to edit a file you need write access on the file, but to create a file you need write access on the folder.

largo
04-02-2008, 10:29 AM
Yes, thanks jsebrech :), the problem was with the folder's permission.