Page 1 of 1

Windows / Apache / PHP & Permissions

Posted: Sun Nov 22, 2015 1:59 pm
by diseman
Trying to do a function that requires setting and retrieving permissions, but can't know because Windows 10 is using a different permissions system.

Is there some way that I haven't seen that PHP programmers can overcome that hurdle?

Back in 2 - 2.5 hours after this posting, so please don't expect any reply from me until then.

Thanks!

Re: Windows / Apache / PHP & Permissions

Posted: Sun Nov 22, 2015 3:03 pm
by requinix
What hurdle? What permissions? What is Windows 10 doing differently? What about setting and retrieving permission?

Re: Windows / Apache / PHP & Permissions

Posted: Sun Nov 22, 2015 4:19 pm
by diseman
wanted to set a file to 0444 using (my php script) on my windows 10, but from what I've read you can't check against the permissions on a local machine since windows uses different permissions systems.

Re: Windows / Apache / PHP & Permissions

Posted: Sun Nov 22, 2015 6:05 pm
by requinix
Yeah. NTFS (what you say "Windows") permissions are vastly different and, IMO, vastly superior to standard Unix permissions. Permissions are much finer-grained and can be applied to individual users and groups.

But first, are you sure you need to change the permissions? It's not a good idea to take your Unix permission knowledge and try to blindly apply it to a completely different operating system.
Putting aside the fact that you should almost always rely on inherited permissions (another difference), maybe what you need is to mark the file as read-only? That's a separate attribute on a file beyond its permissions.

Re: Windows / Apache / PHP & Permissions

Posted: Sun Nov 22, 2015 6:12 pm
by diseman
excellent thoughts.

My project will ultimately reside on a linux server, but for now it's on my windows computer on my UniServer w/ apache & mysql.

All I'm trying to do is copy some default files to a NEW user's folder. I also don't want those 4 default files to be deleted by the user. However, they must upload additional files on their own. So, I wanted to distinguish my default files from theirs using permissions. Then, I was just going to disable to DELETE button on the 0444 default files.

Based on that, what do you recommend the best way to do that is?

Thank you.

Re: Windows / Apache / PHP & Permissions

Posted: Mon Nov 23, 2015 3:23 am
by requinix
With Unix permissions, deleting a file uses the parent directory's write permission, and creating a file also uses the parent directory's write permission. So you can't prevent someone from deleting particular files while allowing them to (a) delete other files or (b) create new files. Same dilemma with Windows, actually.
I don't know what those four files are but you should find a way to keep things functional (or at the very least not throwing critical errors) if those files are missing. Or if the user isn't supposed to modify those files either, find a way to not have to have those files around in the first place.

Anyway, this thing is destined for a Linux server? Then just don't worry about what's happening on Windows.

Re: Windows / Apache / PHP & Permissions

Posted: Mon Nov 23, 2015 5:48 am
by Celauran
I've not had to do this in a while, but wouldn't setting the sticky bit on the parent directory allow the user to create and delete files within the directory while preventing them from deleting the files that were initially copied over as they do not own them?

Re: Windows / Apache / PHP & Permissions

Posted: Mon Nov 23, 2015 7:14 am
by diseman
Good morning sir,

This morning, I thought why not just check to see if the file name is one of the files placed by default and then disable the delete button if that is true.

Problem I'm running into now is the files are listed by means of:

Code: Select all

foreach ($file_list as $file)
and when one of the values = true, all the files listed have a 'disabled' button placed next to them and not just the one I want. I understand why it's doing that, just trying to figure out how to overcome it. :)

Thoughts?

P.S. I'm still gonna look at your previous post as a solution. I just woke-up thinking my way was good and easy and wanted to try it.

Re: Windows / Apache / PHP & Permissions

Posted: Mon Nov 23, 2015 7:22 am
by Celauran
You'd need to post more than a single line of code for me to understand what you're referring to.

Re: Windows / Apache / PHP & Permissions

Posted: Mon Nov 23, 2015 7:32 am
by diseman
thank you for your time and help ...

Code: Select all


$dir = "../_documents/".$_SESSION['users_id']."/";
	$file_list = glob($dir.'*.*');
	natcasesort($file_list); // case-insensitive sorting: http://php.net/manual/en/function.natcasesort.php

echo " \n\n";

	foreach ($file_list as $file) {


if (basename($file == 'hello.pdf')) {

echo

"<form name=\"delete\" method=\"post\">\n".
"<td><input type=\"submit\" value=\"Disabled\" class=\"btn_acp\" diabled><input type=\"hidden\" value=\"".$file."\"/></td> \n".
"</form>\n\n";

} else {

echo

"<form name=\"delete\" method=\"post\">\n".
"<td><input type=\"submit\" value=\"Delete File\" class=\"btn_acp\"><input type=\"hidden\" name=\"delete\" value=\"".$file."\"/></td> \n".
"</form>\n\n";

}


Re: Windows / Apache / PHP & Permissions

Posted: Mon Nov 23, 2015 8:37 am
by diseman
I got it. rather than mess with it in the loop, I accounted for the file, I didn't want to delete, in the $_POST['delete'];