1

I have Ubuntu 18.04 and Laravel. In post method - upload file, I want to save parameters from upload files. At the begin I try to save something in the file:

public function settingsEdit($parameter)
{
        file_put_contents('/tmp/aa.log', 'll');

        return view('pages.account.settings.edit', ['user' => $this->user(), 'parameter' => $parameter]);
}

There is no error, but file isn't created. In tmp directory doesn't exists file aa.log.

2
  • 1
    Or even use the logging system : laravel.com/docs/5.8/logging Commented Mar 5, 2020 at 15:13
  • 1
    You may want to consider adding some error handling around the file_put_contents() call. According to the docs: "This function returns the number of bytes that were written to the file, or FALSE on failure." You should consider reading the value returned by file_put_contents() to ensure you are not receiving an error. For example: if(FALSE === file_put_contents('/tmp/aa.log', '11')) { exit("Error writing file!"); } Commented Mar 5, 2020 at 15:18

1 Answer 1

1

You're using laravel, so you can do Storage::put('/tmp/aa.log', '11'); and you're file will be created in the storage folder, which is the default file location in Laravel.

Or maybe try to use https://github.com/rap2hpoutre/laravel-log-viewer package which create one log file every day.

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

Comments

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.