-3

I am using PHP to generate a csv file with a first name and second name.

On my local XAMPP server it works fine and generate this output.

Andy,Murray
Sarah,Palin
Bob,Saget

However on this 000webhost.com free webhosting site I get the following output.

    <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br />
<b>Warning</b>:  array_walk() [<a href='function.array-walk'>function.array-walk</a>]: The argument should be an array in <b>/home/a2806375/public_html/csv.php</b> on line <b>15</b><br />
<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table>
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

This is my code:

function outputCSV($data) 
        {
            $outstream = fopen("php://output", "w");


            function __outputCSV(&$vals, $key, $filehandler) 
            {
                fputcsv($filehandler, $vals); // add parameters if you want
            }
            array_walk($data, "__outputCSV", $outstream);
            fclose($outstream);
        }



        $result = $db->fetch_array($result);

        header("Content-type: text/csv");
        header("Content-Disposition: attachment; filename=guestlist.csv");
        header("Pragma: no-cache");
        header("Expires: 0");


        outputCSV($result);

Why is it doing this?

Is it because its a free hosting site and they are trying to put advertising in a CSV file?

How do I work around, I am a bit low on money atm so I cant afford a paid server. Thanks

tomaytotomato
  • 3,788
  • 16
  • 64
  • 119
  • 8
    Well read the "html crap" and it'll tell you what's wrong. – sachleen Oct 16 '12 at 20:09
  • Why is it working on my localhost then? – tomaytotomato Oct 16 '12 at 20:10
  • 3
    Probably because you have something in the database on your localhost. – Pitchinnate Oct 16 '12 at 20:11
  • I turned off error reporting but I am still getting the google analytics bit. – tomaytotomato Oct 16 '12 at 20:14
  • 1
    You don't actually show what line 15 is where the array_walk() is called - this may not be DB related, but code that comes earlier in your csv.php – ernie Oct 16 '12 at 20:15
  • Updated with my function that is giving the warning message – tomaytotomato Oct 16 '12 at 20:16
  • `var_dump($data)` in the function - whatever you're passing to it is not an array. – ernie Oct 16 '12 at 20:17
  • Array ( [0] => Bob [first_name] => Bob [1] => Saget [second_name] => Saget ) – tomaytotomato Oct 16 '12 at 20:18
  • 1
    So, is that array_walk line in the code you posted line 15 from csv.php? and is that var_dump from the server or your local version? Finally, here's a thread on disabling the analytics: http://stackoverflow.com/questions/2268868/webhoster-inserts-a-javascript-which-brokes-my-code-how-to-remove-it – ernie Oct 16 '12 at 20:20
  • Thanks ernie, it turns out there was a difference in my db class file in localhost which used fetch_assoc instead of fetch_array. I really need to get some sort of versioning control. – tomaytotomato Oct 16 '12 at 20:24

1 Answers1

1

Disable the insertion of their analytics code from their control panel:

http://members.000webhost.com/analytics.php

From: http://www.000webhost.com/forum/faq/7894-faq-frequent-ask-questions-guide.html

coderabbi
  • 2,261
  • 16
  • 18