Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

Why is a website trying to open a file on my machine?

Question: Recently I was on a web site, clicked on a link and it redirected me to a "file://" URL. The screen showed folders & clickable links to folders and files that aren't on my machine at all! The question I want to ask is: is this website trying to access my personal files on my computer? Does a "file://" url mean my files somehow became public?

Nope. It's something much more benign and banal.

The author made a mistake when creating that website.

It's an easy mistake to make, and somewhat common - particularly with less experienced website creators - so I'll run down what it is and how they (not you) should fix it.

Become a Patron of Ask Leo! and go ad-free!

Creating and editing websites

First, it's important to understand that websites live on the internet. This might seem obvious, but as we'll see in a moment, it's key to understanding how this particular problem happens.

Web authors can work on websites either directly on the web (remotely) or on his or her computer (locally). If you edit your website on your computer, you must then upload those modified files to the website on the internet. It's often quicker and easier to make modifications "locally" (on your local computer), and then upload the changes when the work is complete.

This is a fairly simple concept, but it's easy to get confused.

How images on web pages work

I'm going to use images on web pages as my example, though this applies to any file that a website might link to - a music or document download, or even a link to another page or site.

I'll use this photo of my dog, Dagmar, as an example.

Dagmar

The page you're viewing now contains a full URL, or link, to that image: https://askleo.com/wp-content/uploads/2015/06/dagmar-300x374.jpg1. You can actually place that link in your browser's address bar and it'll bring up that picture, and only that picture.

HTML, HyperText Markup Language, is how web pages are defined, and when I added that photo, I added HTML instructions that say, in essence, "display the image at this URL, and put it on this page right here".

If this page contained only this text and that image, there would be two separate files involved in displaying it for you: the HTML file containing this text and display instructions, and the image file (the .jpg) those instructions say to display.

Images while editing locally

If a web page is being edited locally - before anything has been uploaded to the internet - the instruction to display an image doesn't work, because the image hasn't yet been uploaded, and is not yet available at that URL.

But it's often on the author's local hard disk.

Many webpage authoring tools will automatically do what they consider to be the right thing by displaying the image from the local hard disk while the page is being edited.

What that means is that instead of the "http:" URL to get the file from somewhere on the internet, the editing software uses a "file:" URL to fetch the image from the author's local hard disk. For example, the "file:" URL for the image above might be "file:\\c:\Users\LeoN\Pictures\dagmar-300x374.jpg", if that's where I was keeping the image before uploading it. While I edit the page on my machine, the image loads and displays properly for me, so I can see what my page will look like.

But only on my machine.

What should happen

When I'm done editing the page, three things should happen:

  1. I upload the photograph to somewhere on the internet.
  2. I, or my webpage editing software, edits the web page to fetch the photo from the internet instead of my local machine.
  3. I upload the web page to my website, where it displays properly for anyone who comes along: both the page and the image are fetched from the public internet.

What can happen instead

The problem you're experiencing is when step #2 doesn't happen.

The image is uploaded to the internet, and the web page is uploaded as well.

But the web page still has instructions to "display the image that's at 'file:\\c:\Users\LeoN\Pictures\dagmar-300x374.jpg', and put it on this page right here".

Except that instruction only works on my machine. In fact, even after uploading everything, that instruction continues to work on my machine, so I might not even notice that anything is wrong.

Of course that instruction fails on your machine, because you don't have a "c:\Users\LeoN" folder, much less a picture of my dog with that exact filename. So the display fails on everyone's machine except mine.

What the web page author needs to do

Hopefully, it's clear by now that if you want something to be accessible to anyone on the internet, it needs to be on the internet. That means it needs to be:

  • Uploaded somewhere public
  • Referenced from that location

As a web page author,  I need to make sure not only that step 1 happens - files are uploaded to somewhere publicly accessible on the internet - but that step 2 happens as well. That means that the references I place in my web page are correctly updated to access those files from their public location.

If you find a "file:" reference in a webpage, it's likely the author has simply forgotten that step.

Other than letting the web page author know, there's little you can do.

If you're the author

I'd love to give you specific instructions on how to avoid or correct this error, but unfortunately, it all depends on exactly how you author your web pages and what tools you use.

My experience is that this happens most often and most easily in tools that hide the HTML and other details of what it means to create web pages. Check your tools for options that will:

  1. Automatically upload images or other files referenced in your web pages when you  publish.
  2. Update the references to those images or files in the pages to the uploaded copies.

And since this is such as easy thing to overlook when you're viewing your published page on the same computer on which you wrote it, consider using a different computer to view the page before telling the world about it, as a test.

Do this

Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.

I'll see you there!

Podcast audio

Play

Footnotes & references

1: The actual link may have been modified by website cache software, but the concept still works and applies, regardless of the specific link.

6 comments on “Why is a website trying to open a file on my machine?”

  1. I have a simple web site that I use to post class assignments for my students. I solve that problem by using relative references to my files. For example, instead of specifying “file:\\c:\Users\LeoN\pictures\dagmar-300×374.jpg” I specify something like “pictures\dagmar-300×374.jpg” where the pictures subfolder is located in the same folder as the .html file referencing it both on the internet and on my computer. Could there be a problem with this down the line?

    Reply
    • That will work. Using a relative path makes it so that you could even switch domains and all paths will still work – because the HTML fills in the blanks for the website URL. Really, the only reason to use an absolute path (one that starts at the beginning with http:// or file://) is so that anyone who copies or steals your content will be delivering full paths (and therefore traffic) to your webpage :)

      Reply
  2. I also keep my website simple, using just plain html in an ascii editor.
    Don’t have to learn any fancy tools, or update them, etc.
    Complete freedom to make what I want. Don’t see the benefits of complicated page layout anyway.
    I always start uploading pictures and documents to a server folder that I can use in relative url-addresses, for these files do not change while I’m writing the page code, and I have to upload them anyway.
    Then I write, edit and test the pages locally, with the file-urls of the pictures and documents “out there”.
    When all is fine, I upload the pages and test them live.
    Simple, quick, and I never have to wonder about the fancy concepts the tool makers invented, hiding html code to confront you with things much more complex and often poorly documented.
    Progress… my foot.

    Reply
    • I’m glad to see that I’m not the only one who prefers to code by hand. My favourite editor is Windows Notepad. Since none of the text editing tools in any Word Processor are going to be of any use, I figure, why not just keep the whole thing simple as use Notepad. But the biggest reason I do so is because I have never found a webpage editor program that will let me create the page exactly the way I want.

      I have a lot more control over the layout when I code by hand. And it’s fun to learn new stuff. I’m starting to dabble in CSS.

      I test my webpages both before and after uploading in both Firefox and Internet Explorer to ensure they display the way I want them to. Often times also checking on my laptop and my desktop computer since both have different display settings (SVGA vs XGA? — wide-screen).

      Reply
      • I use a free app called SeaMonkey to edit my website, it’s easy to use and has a browser built in, so I don’t have to switch to another browser to see if it looks ok on the web. Makes me look like a pro (which I’m not :) )

        Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.