0

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.

1 Answer 1

1

Try changing

$latest_filename = $entry;

To:

$latest_filename = $path.'/'.$entry;

You're inside $path looking for your file, but when you try to reach it, you need to go inside $path again, otherwise you'll never find it.

Sign up to request clarification or add additional context in comments.

1 Comment

Damn my bad, ahahahahah didnt see that one!! Thank you very much for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.