I think the problem is that the output file isn't being created correctly. That would explain why it works on the server (where I manually create it) but not when php is running. Maybe php doesn't have permission to write into the public folder, for some reason?