I had the same problem. I thought a file would be created if I use w or w +, but give me the error above.
So the problem was that we needed to create a directory before we could create a file.
We can get the absolute path of the DIR file
$dir = dirname($filename);
Create DIR
//if(!is_dir($dir)) mkdir( $dir , 0755, true);
The third parameter is important, you want to recursively
I know this sounds silly, but it can save the time added here.
source share