Monsieur Mark
Monsieur Mark

Reputation: 301

PHP file in wordpress generating json file for fusioncharts

In WordPress, I have a FusionCharts div in a page called "JSON" that points to a file called jsontest.php. jsontest.php contains the following code that generates a JSON file.

<?php

$result=mysql_query ("SELECT date, last_close_eur FROM pricing limit 10");

$i=0;
while($row=mysql_fetch_array($result)) { 
    $response[$i]['DATE']  = $row['DATE']; 
    $response[$i]['LAST_CLOSE_EUR']= $row['LAST_CLOSE_EUR'];
    $data['posts'][$i] = $response[$i];
   $i=$i+1;
} 

$json_string = json_encode($data);

$file = 'file.json';
file_put_contents($file, $json_string); 
?>

Output file does not contain any data. Any idea?

Upvotes: 0

Views: 1565

Answers (1)

hindmost
hindmost

Reputation: 7195

Try this:

...
$file = dirname(__FILE__). '/file.json';
file_put_contents($file, $json_string); 

Upvotes: 3

Related Questions