Jump to content

[SOLVED] Mkdir function shows Permission denied


macattack

Recommended Posts

I have the following code,

 

if($_POST['save'] == 'Save'){
	if(!is_dir(DIRECTORY_LISTING.'/'.$_POST['dir'])){
		mkdir(DIRECTORY_LISTING.'/'.$_POST['dir'], 0777, true);
	}
$fp = fopen(DIRECTORY_LISTING.'/'.$_POST['blog'], 'w');
fwrite($fp, $_POST['content']);
fclose($fp);
echo "Blog entry saved/updated<br><br>";
}

 

which references the following function:

function displayAddNewBlogForm(){
	echo "<a href='index.php'>".BLOG_NAME."'s Editor Home</a><br>";
	$monthWritten = date("F");
	$month = date("m");
	$day = date("d");
	$year = date("Y");
	$hour = date("H");
	$minute = date("i");
	$name = $_POST['title'];
	echo "<p1>Add new blog entry for $day $monthWritten, $year $hour:$minute";
	if(is_file(DIRECTORY_LISTING."/$year/$month/$day/$hour $minute")){
		echo "You've already created a blog entry in the last minute. Try deleting it or editing it instead!";
	}
	echo "<form action='index.php' method='POST'>";
	echo "<input type='hidden' name='blog' value='$year/$month/$day/$name'>";
	echo "<input type='hidden' name='dir' value='$year/$month/$day/'>";
	echo "<label for='title'>Post Title</label><input type='text' name='title'><br>";
	echo "<textarea name='content' cols='100' rows='15'>Write your post here</textarea><br>";
	echo "<input type='submit' name='save' value='Save'> ";
	echo "</form>";
}

 

When I try to save the post, I get the following message: "Warning: mkdir() [function.mkdir]: Permission denied in /Users/username/Sites/PHP Blog/edit/index.php on line 9"

 

I don't know if it makes a difference, but I am running OS 10.5.2

 

Thanks in advance for any help.

Link to comment
Share on other sites

Not a PHP problem, I don't think.  I'm going to be that it's as simple as the directory permissions on your wwwroot.  If it's a *Nix box: chmod 777 /path/to/root/dir.  Depending on how you created the files, you may not be the owner and thus may not be able to modify the files.  In which case, you'd need to do chown.

 

When you say "OS 10..." does that mean a Mac?  In which case, I know nothing about them and may have typed all that in vain.

Link to comment
Share on other sites

apache runs as it's own user by default. If you own the directory, but apache tries to write to it, it will be denied. You can either chmod 777 or you can check your httpd.conf file to check/change apache's user/group values.

 

If you change your conf, remember to restart your server before testing.

Link to comment
Share on other sites

I'm not aware of how to do this chmod operation. I did a quick check on Google, but I guess my knowledge isn't that great. And yes, 10.5.2 is the latest Mac OS.

 

If someone has another suggestion and/or can explain a little more about how to make this change, that'd be wonderful.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.