What is the Difference and how can i fix this.
Why does this one work
$backupFile = file_get_contents("listbackup.json");
file_put_contents('list.json', $backupFile);
And when i use it like this it wont work.
This one is above HTML
session_start();
if(!isset($_SESSION['active']))
{
$backup=fopen("backup/".time().".json", "w");
fwrite($backup, json_encode($list)); fclose($backup);
if(isset($backup))
{
$_SESSION['active']=true;
}
}
And this one goes after
session_start();
if(isset($_SESSION['active']))
{
$path= "backup";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read()))
{
$filepath = "{$path}/{$entry}";
if (is_file($filepath) && filectime($filepath) > $latest_ctime)
{
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
}
}
$latest=file_get_contents($latest_filename);
file_put_contents('list.json', $latest);
session_destroy();
}
When i try to get the content from the $latest_filename its gives me a false Bool and i cant get any further with it. What i need is to put the content in list.json thats all.