PHP "copy" not working on my Server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Largo65
Forum Newbie
Posts: 4
Joined: Fri Mar 07, 2008 4:44 am

PHP "copy" not working on my Server

Post by Largo65 »

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? :?:

Code: Select all

<?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); 
} 
?>
thaynejo
Forum Newbie
Posts: 14
Joined: Tue Apr 01, 2008 9:06 am

Re: PHP "copy" not working on my Server

Post by thaynejo »

Permissions is where I would start. I would check the folder permissions as well. (though not recommended, you can set the folder permissions to 777 and see if it works. That should narrow down whether it is a permissions issue or code issue at least)
Post Reply