Hello guys I'm trying to read a file copy content into a new file to a random directory:
   <?php 
    error_reporting(E_ALL);
$dirname = uniqid();
mkdir($dirname);
$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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.