I am currently working on this project which requires me to make a function which dinamically decides the directory name and then creates a simple .txt file in that directory.
my code is as follows:
($destinatario is a string)
$diretorio="../messages/".$destinatario;
if (is_dir($diretorio)) {
;
}else{
mkdir($diretorio);
}
$path=$diretorio."/".$data.",".$assunto.",".$remetente.".txt";
$handle=fopen($path,'w+');
fwrite($handle, $corpo);
fclose($handle);
nevermind the portuguese, but the bottom line is that it should create a .txt file using the naming guidelines i’ve provided. The funny thing is that when i do this, php creates this weird file whose filename is “01.09.2010 04”
(with no extension at all) which amounts to the first few characters of the actual filename i’d like to create…
edit($data is actually the output from a call to date(“d.m.Y H:i”))
Per comment by OP:
The problem is the
:character. (Still, there may be other illegal characters in the other parts composing the final file name.)EDIT
The essence of the problem and solution is in the comments to @tchen’s answer. Keep in mind that colon is a valid file name character on (some? all?) *nix platforms but is invalid on Windows.