2

Background: Me and my two colleagues all have a folder on ours computer called: C:\Synkade filer. So any file that is there, we all have access to.

Now I have created a small MySQL database that saves the path to a file on that local folder, for instance C:\Synkade filer\pdffiles\file1.pdf

The php script I made has no problem in uploading new files into the *C:\Synkade filer\pdffiles* and saving the path information into MySQL. The idea is that when I click on a small pdf-icon the php script will get the path information from MySQL and open the file on the browser (firefox). Say the path information in MYSQL is: C://Synkade filer/pdffiles/file1.pdf The retrieving code is:

<a href="' . $row['fup']. '"><img src="./images/pdf_icon.gif" width="16" height="16" border="0" alt="PDF file" /></a>

, where $row['fup'] is the row information from MySQL.

The problem is that this doesn’t work. Is it because the file is on a local drive (C:)?

Before you ask: why not upload the files on my web server? The answer is that I would prefer not to. The pdf files do have sensitive information that we three only show have access to. So it feels better that the pdf files are only accessible to us on our own computers. The point is also that if someone else tries to open the pdf file, it simple will not find it since it will not exist on his/hers device.

So my question is: Is there a way to make the access to the files from a local drive to work. Is this a script problem or is this a computer configuration issue?

I need to say that this is my first PHP-MySQL database ever, so my knowledge is limited. I am thankful for any help I can get.

user1138626
  • 37
  • 2
  • 4

2 Answers2

3

Sure: just write out a "file" URL format link to your .pdf file.

For example:

file:///C:/temp/ececnews.pdf

Corresponds to the windows file "c:\temp\ececnews.pdf"

Two handy functions are urlencode() and realpath():

paulsm4
  • 114,292
  • 17
  • 138
  • 190
3

Use file:/// in front of the path of your file.

http://www.w3schools.com/html/html_url.asp

For example:

<a href="file:///' . $row['fup']. '"><img src="./images/pdf_icon.gif" width="16" height="16" border="0" alt="PDF file" /></a>
Mathieu Dumoulin
  • 12,126
  • 7
  • 43
  • 71
  • Hello Mathieu Dumoulin! Say the MySQL saved path info is: **C://Synkade filer/pdffiles/file1.pdf**. Then your suggestion will generate: **file:///C://Synkade filer/pdffiles/file1.pdf** when I move the mouse over the pdf-icon. But when I click on it nothing happened. No error information, no nothing! Is it something else I am missing? Thanks beforehand! – user1138626 Jan 09 '12 at 21:12
  • Why do you have C://, it should be c:/ – Mathieu Dumoulin Jan 09 '12 at 21:24
  • 1
    Spaces in path names can make you sad. Please look at my suggestion about "urlencode()" above. And yes, it should be "file:///C:/xyz/myfile.pdf", not "C://". Here's another good link: http://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-and-when-to-20 – paulsm4 Jan 09 '12 at 21:28
  • C://Synkade filer/pdffiles/file1.pdf was actually working for the upload process to MySQL Anyway, I have tried with just C:\ but still nothing happened when I precc the icon. I have just in order to remove Spaces tried another folder: file:///C:/test/pdffiles/file1.pdf but still nothing – user1138626 Jan 09 '12 at 21:55
  • I just discovered something! When I did copy the link address and pasted it to a new window in the firefox it could successfully open the pdf file. So now I guess it is something else wrong with the linking process. I just wish I knew what : ) – user1138626 Jan 09 '12 at 22:13