简体   繁体   中英

file url handling in PHP

Some background. I am using XAMPP on my laptop as a standalone, single-user server. I have a PHP/Ajax/JavaScript application that to all intents and purpose is a contacts and contact management system.

At the moment, web links are linked to the records as they are displayed to provide relevant content which the user selects by clicking the hyperlink. I would like to have the ability to include file links as well. So to my question:-

I have a file URL of the kind file: ///G:/home/scans/passports/tony0001.pdf which works as expected when typed into the address line of Firefox and Chrome, ie it fires up Adobe Reader and opens the PDF file. I use PHP to generate the relevant anchor statement using the information retrieved from the application. I give the href below:

href=file://G:/home/scans/passports/tony0001.pdf 

The link does display as a URL and if I hover the cursor over the link it shows the correct File URL. If I click on the URL nothing appears to happen. I don't see any error messages.

So, my question is, is there a PHP.INI option I need to set to allow this? The functionality I am looking for is to be able to embed any sort of URL into my application and have it fire up the right handler and file.

I understand the point made regarding a potential security issue, but as I explained, I can type the file URL into the browser page and it opens as expected.

Update 16/10/15 The solution to this is to embed a windows shortcut which points to the target document in the xampp/htdocs directory (or a sub-directory). The links then work correctly using the very simple form of href=tony0001.pdf

浏览器禁止本地文件访问,例如file://因为这会带来安全风险。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM