SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    CSS and Absolute Paths

    I would like to use an absolute path to link all my pages to a single CSS file.

    But when I try this out (testing pages on my own computer, with the HTML and CSS files located on a thumb drive), it acts as if the file doesn't exist.

    I know it's not a typo, I know the file is actually there, etc. etc.

    So, basically, absolute paths just can't get to thumb drives? (I guess it's a silly question; everything works fine when I upload it to the server.)

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,445
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    A browser uses HTTP and an OS uses the filesystem. I have no trouble with paths when it's within the localhost, but I have never tried it to another drive. You may get it to work using something like
    href="file:/E/file.css" (or "file:\E\file.css" with Windows) instead of "http://", but I thiink the easiest thing to do would be to place a copy of the file within the localhost.

  3. #3
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    None of the files are on a server, yet; they're all resting safe on the thumb drive (within the XAMPP htdocs file, so that I can test the PHP).

    The css file is located at H:/xampp/htdocs/styles/file.css (No http)

    But for some reason, the following doesn't work:

    Code:
    <link href="H:/xampp/htdocs/styles/file.css" type="text/css" rel="stylesheet" />
    As I said, using absolute paths once everything's moved to the server...

    Code:
    <link href="http://www.mydomain.com/styles/file.css" type="text/css" rel="stylesheet" />
    ...works great. So the only trouble I'm having is while I'm designing the site on my local computer. I could just use relative paths until I move it online, but that seems like the coward's way out. What I'd like to do is just use PHP's $_SERVER['DOCUMENT_ROOT'] and stop thinking about it. Is it still doable?

  4. #4
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't you need to use back slashes for Windows files?

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  5. #5
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Well if you want PHP to do this...(which would be extra work plus if your not using PHP for anything else in the document your making the server work harder by running the PHP through it and "compiling it") then why not post in their forum?

    I'm a coward-relative it is.
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  6. #6
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,797
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Isn't it something like this on windows.

    Code:
    <link href="file:///E|/xampp/htdocs/styles/file.css" type="text/css" rel="stylesheet" />
    http://en.wikipedia.org/wiki/File_URI_scheme

  7. #7
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Well this is opening up a local file on my desktop
    Code:
    file://localhost/C:/Documents%20and%20Settings/Ryan%20Reese/Desktop/asdfasdfthisisnewbbbbb.html
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  8. #8
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,797
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by RyanReese View Post
    Well this is opening up a local file on my desktop
    Code:
    file://localhost/C:/Documents%20and%20Settings/Ryan%20Reese/Desktop/asdfasdfthisisnewbbbbb.html
    localhost is assumed if omitted and the colon is changed to a bar for conformance which also leaves you with the example I posted

  9. #9
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    39,797
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by RyanReese View Post
    Well this is opening up a local file on my desktop
    Code:
    file://localhost/C:/Documents%20and%20Settings/Ryan%20Reese/Desktop/asdfasdfthisisnewbbbbb.html
    localhost is assumed if omitted and the bar can be used instead of the colon which also leaves you with the example I posted

  10. #10
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Am I the only person thinking this or surely the problem with files not being found might be if the drive letter used is invalid (sometimes Windows likes to reassign drive letters), it would explain why the path isn't displaying the files (as relatively they do exist but absolutely they are invalid due to the drive letter used upon plugging in... which is why I would only ever use relative links on a removable storage device.

  11. #11
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,445
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Good point. I had blocked out the memory of my last crash/reinstall until that jarred my memory. But one of the (many) pains I encountered was a temporary virtual drive taking up a drive letter that caused the others to get "bumped around" a bit.

    I don't know how I'd go about figuring out where the localhost server would need to reference it if I absolutely had to. A long grueling session of trial and error I guess. Unless someone else in a forum happened to know.

  12. #12
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    gary.turner: Iíve always used forward slashes while working on my Windows XP, and it never gave me trouble before. Plus, I went through and tried the various options with backslashes instead of forward slashes; still no go.

    RyanReese 1: The project Iím working on consists almost entirely of PHP-built pages, so I wonít just be calling the one variable (that would be silly). But the problem seems to be with the address itself, not that PHP is piping it in. Even when the absolute path is just typed into an HTML file, it still wonít load. I wasnít sure where to go with a path question; because I was using it with a CSS <link>, I decided on here.

    Paul OíB: Tried that after reading your suggestion. Still didnít work.

    RyanReese 2: Frustratingly enough, this does work, while Paul OíBís didnít. After much guesswork and experimentation, I discovered that if the HTML file is located on a thumb drive (regardless of where the CSS file is located), then absolute paths (referring to other parts of the localhost) donít work. But if the HTML is somewhere on the actual computer, such as C, then (even if the CSS is on a thumb drive!) it can use absolute paths. Itís annoying.

    AlexDawson: When Iím testing the HTML in a browser (I use Chrome), it canít locate the CSS. This seems to point to your being right Ė the thumb drive isnít using a ďrealĒ letter, because itís not a "real" drive? (I probably donít have the vocabulary right; I donít know very much about this side of computers. But I do recall this coming up when installing XAMPP. It said NOT to designate a permanent drive letter if it was going on a thumb drive, which it was, because [I assumed] those letters can change.)

    However, when I direct my browser to H:/xampp/htdocs/styles/file.css, it downloads the CSS into "My Documents/My Downloads" just fine. Also, why would display correctly when the HTML is in C, but the CSS is in H, as I mentioned above? And, why would the browser be able to locate the HTML, but not the CSS?

    (Thank you all for the time and help, btw.)

  13. #13
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    I believe the problem lies in the way that your system is treating fixed drives vs variable drives (ie usb assigned drives). I don't believe you can hard code fixed paths to variably assigned drive names. I've attempted that in the past and have never had success.

    In the long run, you'll be better off dealing with absolute paths based off the root of the web site anyways. If you define and reference from the root structure, then your structure can migrate from one location to the next (ie localhost to production server) without having to remember to make additional changes.

    Edit:

    This link is related to .net, but the answer matches what I thought - the mapped letter is for you while the web servers run under a different account and the drive isn't mapped for them.

    http://www.eggheadcafe.com/conversat...eadid=29572924
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •