最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Open A File Via Html Button - Stack Overflow

programmeradmin1浏览0评论

I am looking for a way to open a file when user clicks on the open button on my website.

Basically, I want to define the path to that specific file that I want the html button to open.

I am looking for a way to open a file when user clicks on the open button on my website.

Basically, I want to define the path to that specific file that I want the html button to open.

Share Improve this question edited Aug 22, 2016 at 9:04 worldofjr 3,8868 gold badges39 silver badges52 bronze badges asked Aug 19, 2016 at 18:19 Tanmay GoyalTanmay Goyal 311 gold badge1 silver badge2 bronze badges 1
  • open a file WHERE? on their device? some other site? – Marc B Commented Aug 19, 2016 at 18:20
Add a ment  | 

4 Answers 4

Reset to default 2

I have read about it in another post. Try using this:

<a href="path_to_file" download="proposed_file_name">Download</a>

Where :

path_to_file is either an absolute or relative path, proposed_file_name the filename to save to (can be blank, then defaults to the actual filename).

Hope it helps

<a href="/filepath/file.pdf" target="_blank"><input type="button" value="Open File" /></a>

Using

<input type="file" id="file" name="file" />

you can open up a file dialog. You'll have to handle this with PHP. This link: https://www.sitepoint./handle-file-uploads-php/ provides all the info you need. If you don't have a server to upload .php files to, you can set up a LAMP server.

Hope this helps :)

You can use this in the button:

onclick="window.open('file_url')"
发布评论

评论列表(0)

  1. 暂无评论