w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
PHP file_put_contents works with file, no file gets "failed to open stream: No such file or directory"

When the file doesn't exist, you are prepending ../ to the path, thus you are trying to write to:


Are you sure that the folder ../../templates exists (and that PHP can write to it)?

Before you write to a file, you need to check that the folder exists. Try using is_dir():

    file_put_contents($file, $file_contents);

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.