`/ storage / emulated / legacy /` vs `/ storage / emulated / 0 /` vs `data / data / myApp '

Это взято выше, например, и переместило его на php. Это переместится в конец файла и добавит новые данные без чтения всего файла в память.

// read the file if present
$handle = @fopen($filename, 'r+');

// create the file if needed
if ($handle === null)
{
    $handle = fopen($filename, 'w+');
}

if ($handle)
{
    // seek to the end
    fseek($handle, 0, SEEK_END);

    // are we at the end of is the file empty
    if (ftell($handle) > 0)
    {
        // move back a byte
        fseek($handle, -1, SEEK_END);

        // add the trailing comma
        fwrite($handle, ',', 1);

        // add the new json string
        fwrite($handle, json_encode($event) . ']');
    }
    else
    {
        // write the first event inside an array
        fwrite($handle, json_encode(array($event)));
    }

        // close the handle on the file
        fclose($handle);
}
16
задан CommonGuy 13 May 2014 в 08:46
поделиться