Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:52:33+00:00 2026-06-08T23:52:33+00:00

complete Novice to PHP and HTML so this could be a schoolboy error. I’m

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:52:34+00:00Added an answer on June 8, 2026 at 11:52 pm

    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 ?

    elseif ($os == "Mac")
    {
        print_r("mac os was found");
        // your code
    }
    

    For your code, if/else is not very important, you can do that :

    <?php
        // First step: you detect OS plateform : 
    
        //determine OS of user MAC or PC and add "pathOsFile" var:
        $user_agent = getenv("HTTP_USER_AGENT"); 
        if (strpos($user_agent, "Win") !== FALSE){
            $os = "Windows"; 
            $pathOsFile = "file:///";
        }else if((strpos($user_agent, "Mac") !== FALSE) || (strpos($user_agent, "PPC") !== FALSE)){
            $os = "Mac";
            $pathOsFile = "file:":
        }
    
        // Second step: You display all your file...
    
        //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='".$pathOsFile.$file."'>".preg_replace("/\\.[^.\\s]{3,4}$/", "",basename($file))."</a><br><br>"; 
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

having some trouble trying to figure this out, complete novice when it come to
So, to preface, I'm a complete novice at this Excel business. I've found similar
I am trying to get a HTML/PHP form to submit properly. Some details: base
complete novice at work (who is also ill and feeling particularly thick) I have
I am a complete novice to image processing, and I am guessing this is
I am a complete novice in C++. I am trying to read a file
I am a complete novice at HTML as i decided to skip it and
I'm desperately hoping someone can assist me with this error. Admittedly, I'm a novice
I am a complete novice at php and postgres. I have been searching all
First off, I'm a complete novice as a web developer. I have a PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.