1

How can I link to a local file in PHP?

I've tried all of these, but nothing works to prompt a file-download.

According to: http://php.net/manual/en/wrappers.file.php

I can add: file:///

But my editor doesn't like that when I also add the \ to designate the folder-structure, and the page then fails to load.

$path = "file:\\\E:\machine\files\months\";
$path = "file:\\\E:\\machine\\files\\months\\";
$path = "file:\\\E:/\machine/\files/\months/\";
$path = "file:\\\E:/machine/files/months/";

None of those work -- either the page fails to load, or the slashes aren't going the correct direction for local paths.

How can I link to a file on a local machine? (yes I know it will only work if the path structure is exactly the same)

Thanks

EDIT -- The issue isn't the filename. I add that later and that works fine. The issue is my syntax with path AND/OR file:///

My editor complains about file:///
https://i.stack.imgur.com/z4lRI.jpg

BeMy Friend
  • 751
  • 1
  • 6
  • 11
  • In all of those cases, you still need the actual file name at the end of the path. E.G. `$path = "file://E:/machine/files/months/download_file.pdf"` Is that being added later in the script? – larsAnders Apr 08 '16 at 05:50
  • Yes, the filename is added later on and that works correctly. The problem is my syntax with the direct path. As I said, either my slashes aren't added correctly, or the page fails to load. My issue is not related to the filename. – BeMy Friend Apr 08 '16 at 06:03
  • What you posted doesn't work either. My editor complains about "file://" or "file:///" See: http://imgur.com/uEaxgnM – BeMy Friend Apr 08 '16 at 06:08
  • Ok, your editor is complaining, but does the code work? You might try single quotes instead of double quotes. – larsAnders Apr 08 '16 at 06:10
  • I've tried single quotes and double quotes. Here is a screenshot of the code, and then of the result in Mozilla. Look at the Mozilla view. The slashes are going the wrong way regardless of the direction I put them in the code: http://imgur.com/4kSGgLj Slashes for a local path need to go \ not / – BeMy Friend Apr 08 '16 at 06:23
  • Or you can just learn something new.... Danged direction of slashes apparently doesn't matter. "Doh!" In all my years using a PC, I never knew Windows could interpret local paths with the forward slash. Dang... Thanks – BeMy Friend Apr 08 '16 at 06:37

0 Answers0