0

I'm having an issue where the following php script works as expected and writes the following array data to a csv file on my local machine, but when I upload this script to the server the csv file (located on the server) isn't written to when expected.

<?php
    $csvData = array($info1, $info2, $info3, $info4, $answer4, $answer5, $answer6, $answer8, $answer9, $answer10, $answer12);
    $fp = fopen('data.csv', 'a');
    fputcsv($fp, $csvData);
    fclose($fp);
?>

Thank you in advance for any help.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
12th
  • 11
  • 3
  • Has The Folder or File the right Permissions ? – Marcel Mar 07 '14 at 20:09
  • As far as I know, it should. I have done this before on the server with success. – 12th Mar 07 '14 at 20:13
  • What is the error message? – ficuscr Mar 07 '14 at 20:17
  • 1
    `if (!$fp) { die("unable to open file for output"); }` would help a lot... – Marc B Mar 07 '14 at 20:22
  • @ficuscr Thanks for your reply. I had not checked the error message prior, good thinking. I get the following: Warning: fopen(data.csv) [function.fopen]: failed to open stream: Permission denied in mysite.php on line 693. Does this mean it is a problem with the server permissions after all? – 12th Mar 07 '14 at 20:34
  • yes. Check folder permissions. I assume you are using same config? – ficuscr Mar 07 '14 at 20:35
  • @MarcB Thank you very much for the tip. Well, now I get your error message. Does this mean the server doesn't allow me to open the file? Given that the same script works on my local machine? – 12th Mar 07 '14 at 20:36
  • @ficuscr thank you again, I'm gong to do that now. – 12th Mar 07 '14 at 20:38
  • yes. could be a permissions things. `is_writable()` will answer that. – Marc B Mar 07 '14 at 20:51

0 Answers0