I searched, searched and did extensive debugging, and for me life cannot understand why fputcsv does not work for me.
I can successfully open the .csv file and write to it.
My debugging proves that the array is loaded correctly and that the foreach loop is working correctly. However, the fputcsv function does not write anything at all. I deleted all lines that might cause problems, such as URLs, etc., but they still wonβt write.
I am the only person with access to this environment, so I know that this is not a file lock conflict. I can create a file and write to it, so I know this is not a problem. And I get the debug output from the foreach loop, so I know that this is not a problem with an array or loop.
I have provided my code and debug log below ...
$posts_meta = array( 'twitter_title' => $this_title, 'twitter_brandtag' => $this_brandtag, 'twitter_hashtags' => $this_hashtags, 'twitter_iterations' => $this_iteration, 'twitter_timing' => $this_timing, 'twitter_time' => $this_time, 'twitter_id' => $post_id, ); // Debuging file_put_contents("/blog/debug.txt", "About to write CSV file.\n", FILE_APPEND); file_put_contents("/blog/debug.txt", print_r($posts_meta, true)."\n", FILE_APPEND); $myfile = fopen('/blog/pdm_twitter_ouptut.csv', 'a+'); // More debugin file_put_contents("/blog/debug.txt", "myfile handle = ".$myfile."\n", FILE_APPEND); fwrite($myfile, "This file is open and working.\r\n"); foreach ($posts_meta as $fields){ $fresponse = fputcsv($myfile, $fields); // A little more debugging... file_put_contents("/blog/debug.txt", $fields."\n", FILE_APPEND); } fclose($myfile); // And more debugging file_put_contents("/blog/debug.txt", "fputcsv response = ".$fresponse."\n", FILE_APPEND); file_put_contents("/blog/debug.txt", "Just closed CSV file.", FILE_APPEND);
And here is the result of Debug magazine ...
About to write CSV file. Array ( [twitter_title] => World Stocks Up As US Jobs, China Exports Improve [twitter_brandtag] => - FP test 9 [twitter_hashtags] =>
Everything that appears in the CSV file (as you can see in the debugging code above) "This file is open and working."
Any thoughts anyone might have would be greatly appreciated!
Thanks a lot!
Route