Page 1 of 1

Cannot save JSON data with fwrite()

Posted: Sat Dec 19, 2009 8:38 pm
by 4dplane
Hi,

I am able to opening a cache file(.txt), decoding it as JSON and insert a new name&value. All of this works and I have checked many times that the final array is filled with the correct data. What I can't do is write the data to back to the cache file. I have error reporting on but I don't receive any and the the cache file is always the same, never updated. Even if I put "0" in fwrite the file is never updated

Code: Select all

 
***Method to open file and decode it into array******
function openCache(){
        //open the cache imaage into an array
        $this->allMediaHandle = fopen($this->allMediaCacheURL, 'r+') or die("can't open file");//channel info to open
        $this->openAllMediaCache = fgets($this->allMediaHandle);
        //decode into JSON creating a 2D array - dataToSearch
        $this->allMediaCache = json_decode($this->openAllMediaCache, true);
}
 
**** code snippet that inserts a new name&value
$this->allMediaCache[$i]['channel_id'] = $this->ChannelIDsAndMedia[$j][0];
 
****method to write to the cache file and close it******
function closeCache(){
        //echo $this->allMediaCache[$i]['channel_id'];
        fwrite($this->allMediaHandle, $this->allMediaCache);
        //$this->allMediaCache = json_encode($this->allMediaCache); // http://docs.php.net/manual/en/function.json-encode.php
        fclose($this->allMediaHandle);
}

Re: Cannot save JSON data with fwrite()

Posted: Sun Dec 20, 2009 12:17 am
by 4dplane
Wow, it's my hosting service - I have to request that they turn on allow_url_fopen.