appending to a file problem

Discussion in 'PHP' started by ranacseruet, May 12, 2009.

  1. #1
    I am trying to append data at the end of the file.
    
    $myFile = 'test.csv';	
    	$fh = fopen($myFile, 'a');
    	$data = "testdata";
    	fwrite($fh,$data);
    	fclose($fh);
    
    Code (markup):
    But data isn't appending. nothing is happening. why?
     
    ranacseruet, May 12, 2009 IP
  2. diligenthost

    diligenthost Peon

    Messages:
    685
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is the file already created on the server? If so, does it have the correct permissions for it to be written to?
     
    diligenthost, May 12, 2009 IP
  3. ranacseruet

    ranacseruet Peon

    Messages:
    302
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes, the file exits & file permission is set to 0777.
     
    ranacseruet, May 12, 2009 IP
  4. diligenthost

    diligenthost Peon

    Messages:
    685
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try changing:
    This way you'll see if that's what is failing or not.
    Also you could try with an absolute path:
    From a quick look though it doesn't seem like you should be having any problems. Have you checked the error logs?

    I don't think this is the problem, but you could also try putting a space between $fh, and $data, like this:
     
    diligenthost, May 12, 2009 IP
  5. ranacseruet

    ranacseruet Peon

    Messages:
    302
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok, its working now. Thanks
     
    ranacseruet, May 12, 2009 IP