Posted by thehuby on 12/20/05 15:59
I am writing a file using PHP and all is great thus far:
$file_contents = "<?php \n".
"\$file_inc_news_id = '" .$id. "' \n" .
"include( \$_SERVER['DOCUMENT_ROOT'] . '/news/news_item.php' );
\n" .
"?>";
$filename = $_SERVER['DOCUMENT_ROOT'] . "/" .date('his'). ".php";
$fp = fopen($filename , "w"); //to write a new file
fwrite($fp , $file_contents );
fclose($fp);
However I want to add the facility for the file to be written into a
sub directory that may or may not exist - if the folder exists then it
works fine - if it doesn't then it throws an error.
Without having to write a section of code to check if the folder
exists, is there a way of forcing PHP to build any required folders for
me?
Navigation:
[Reply to this message]
|