Page 1 of 1

Create file problem

Posted: Mon May 24, 2004 10:42 am
by rowlandk
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?

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;
	}


}

Posted: Mon May 24, 2004 11:42 am
by delorian
Is your www-server running as nobody? If so you should give the directory in which you are trying to create files write permission, the same with the directory you are creating in this script. e.g.:

Code: Select all

$mkdirresult = mkdir($filepath, 0707);
BTW: What for is the bin2hex function, it converts binary data into string, so if your filename is a string why do you want to convert it :?