Create file problem
Posted: Mon May 24, 2004 10:42 am
I have a function that creates a directory and file if they do not already exist. However it always seems to return false. I till create the directory but not the file.
Here is my code. Any ideas?
Here is my code. Any ideas?
Code: Select all
function makefile($mk_content, $mk_user_id, $mk_filename) {
// Attemp to create the directory
$filepath = "../users/" . $mk_user_id;
if (! file_exists($filepath)) {
$mkdirresult = mkdir($filepath, 0700);
}
// Convert filename to hex
$mk_filename = bin2hex($mk_filename);
// Attemp to create the file
echo $filepath . "/" .$mk_filename . ".txt";
if (! file_exists($filepath . "/" . $mk_filename . ".txt")) {
$file = fopen($filepath . "/" . $mk_filename . ".txt", "w");
fwrite($file, stripslashes($mk_content));
fclose($file);
return true;
} else {
return false;
}
}