How to chown on linux but skip on windows servers

Post Reply
darknkreepy3#
Site Admin
Posts: 247
Joined: Tue Oct 27, 2009 9:33 pm

How to chown on linux but skip on windows servers

Post by darknkreepy3# »

So, if there's a problem with the server not allowing a text file to be saved when modified by some form or shiftable jquery interface, and it was uploaded to a server that isn't a windows system, aka linux... try chown and then chmod.

If your script is tested locally on a windows apache server and uploaded to a shared linux serverm, the "WIN" test will skip if running on windows.

This is very useful when writing code and testing locally in windows, filling up some text files written by the script and then moved with an FTP server to the shared linux server, iPower for example, and then making sure it can be written by the php script and current "owner" while running online.

here is a snippet assuming you know the $file and you made a $saveStr to hold the textfile .txt data you want to save.

Code: Select all

	//save the newly created string
	if(file_exists($file))
		{
		//
		if(strtoupper(substr(PHP_OS,0,3))!='WIN') 
			{
			chown($file,posix_getuid());
			}	
		chmod($file,0755);
		}
	file_put_contents($file,$saveStr);
Post Reply