complete Novice to PHP and HTML so this could be a schoolboy error. I’m trying to set up a small Intranet site for my work. I want to be able to display links to Local Files Eg Comapny Handbooks, Procedures etc. My main issue is that it needs to be both PC and MAC user friendly (Mac users mainly use Firefox, PC’s use IE).I have a PHP script on each page that I can get to work individually for a Mac or a PC but can’t get it working simultaneously. Eg I’d like my code to look up the users OS and the run the part of the script relevant to displaying the Local File link for that OS. I believe the critical part of the script is the ‘file///’ If it’s ‘file///’ it works on a PC in IE & Firefox but it needs to be ‘File’ (without three /’s) to work on a Mac? but I may be wrong in that analogy. Current code as follows;
<?php
//determine OS of user MAC or PC
$user_agent = getenv("HTTP_USER_AGENT");
if (strpos($user_agent, "Win") !== FALSE)
$os = "Windows";
else if((strpos($user_agent, "Mac") !== FALSE) || (strpos($user_agent, "PPC") !== FALSE))
$os = "Mac";
if ($os == "Windows")
{
//path to S:\One reality\Personnel\Culture & Values
$uncpath = "//servername/shared/one reality/personnel/culture & values/";
//get all files with a .pdf extension.
$files = glob($uncpath . "*.pdf");
//print each file name
foreach ($files as $file)
{
echo "<a target=_blank href='file:///$file'>".preg_replace("/\\.[^.\\s]{3,4}$/", "",basename($file))."</a><br><br>";
}
}
elseif ($os == "Mac")
{
//path to S:\One reality\Personnel\Culture & Values
$uncpath = "//servername/shared/one reality/personnel/culture & values/";
//get all files with a .pdf extension.
$files = glob($uncpath . "*.pdf");
//print each file name
foreach ($files as $file)
{
echo "<a target=_blank href='file:$file'>".preg_replace("/\\.[^.\\s]{3,4}$/", "",basename($file))."</a><br><br>";
}
}
?>
The above code runs fine on a PC and opens a new TAB as a pdf but on a Mac the code does not get round to running the Mac specific ‘file:’ without the three slashes and as a result does not know how to display the Local file link. PS I know about allowing local file links in Firefox and that is in place so it’s basically a coding issue. I suspect its something wrong within my IF $os = statement.
I’m preapred to scrap this approach and start again if you think I’ve gone down the wrong route.
for detect Os you can use the “USER AGENT” in php… IF you want , you can read this article, with a script detect os, browser, all details in the user agent….
For your problem in your “else”, have you try to create log in your “else” part ?
For your code, if/else is not very important, you can do that :