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