Hello guys I'm trying to read a file copy content into a new file to a random directory:
$dirname = uniqid();
$newFileName = '/'.$dirname.'/newfile.txt';
$newFileContent = 'someinfoinfile.txt';
if (file_put_contents($newFileName, $newFileContent) !== false) {
    echo "File created (" . basename($newFileName) . ")";
} else {
echo "Cannot create file (" . basename($newFileName) . ")";

and got a no file or directory error.. Where I'm wrong?

Directory is created? Add to line 5 "or die('Cannot create directory')" eg
mkdir($dirname) or die ("Cannot create directory");
check web server error log file. Probably permission denied.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.