json - Unlink file in PHP, then create new one with file_put_contents -
i trying use file_put_contents
put json file in place, finding not overwrite existing file. thinking @ point try , unlink
pre-existing file first, , user file_put_contents
create new one. reason, not seem working. have feeling 2 operations happening quickly, , second step tries run before first step completes. here code:
$filename = '<?php echo site_url() ?>js/salecomps.json'; if (is_readable($filename)) { chmod($filename, 0777); unlink($filename); } $q = $this->db->query("select rollnum , address, v2_lat, v2_lng tblontario municipality = 'ajax' limit 100"); $json_string = json_encode($q->result(), json_pretty_print); file_put_contents('<?php echo site_url() ?>js/salecomps.json', $json_string);
please tell me doing wrong. thanks.
you using wrong way include <?php echo site_url()?>
not give filepath try change
$filename = '<?php echo site_url() ?>js/salecomps.json'; file_put_contents('<?php echo site_url() ?>js/salecomps.json', $json_string);
to
$filename = site_url().'js/salecomps.json'; file_put_contents(site_url().'js/salecomps.json', $json_string);
Comments
Post a Comment