简体   繁体   English

需要从网页下载文件到本地驱动器

[英]Need to download a file from webpage to local drive

I has a requirement like when user clicks on a download button instead of showing the content in browser, i want to save it to the localdisk(perticular location) of the user desktop. 我有一个要求,比如当用户点击下载按钮而不是在浏览器中显示内容时,我想将其保存到用户桌面的localdisk(特定位置)。 Is it possible to do?? 有可能吗? If yes,Please help me with possibilities.. 如果是的话,请帮助我有可能..

Thanks in advance 提前致谢

No a website can't decide where it can save something. 没有一个网站无法决定它可以保存的东西。 Everything goes to download folder by default. 默认情况下,一切都进入下载文件夹。 You have to be using some sort of plugin with permissions or make like browser addon/extension. 您必须使用某种具有权限的插件或使用类似浏览器插件/扩展名。

If you want to prompt download then you could set send headers in php: 如果你想提示下载,那么你可以在php中设置发送标题:

Content-Disposition: attachment; filename="fname.ext" Content-Disposition: attachment; filename="fname.ext" and Content-Disposition: attachment; filename="fname.ext"

Content-Type: application/force-download

Or you could set attribute download to link in html 或者您可以将属性下载设置为以html链接

<a href="file.abc" download>Click Me</a>

Utility of HTTP header "Content-Type: application/force-download" for mobile? 移动设备的HTTP标题“Content-Type:application / force-download”的效用?

http://en.wikipedia.org/wiki/List_of_HTTP_header_fields http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

http://www.php.net/manual/en/function.header.php http://www.php.net/manual/en/function.header.php

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes

You shall just point the file name like this to download. 您只需指向这样的文件名即可下载。

But you cannot decide the path by your code. 但是您无法通过代码确定路径。

<a href="www.tutorialspoint.com/php/php_tutorial.pdf‎">Download the File</a>

Note : Do not try this in jsfiddle or in codepen because they will rename the link with their custom so that the file will be displayed within their output. 注意:不要在jsfiddle或codepen中尝试这个,因为他们会使用自定义重命名链接,以便文件将在其输出中显示。 So, try it in your web server or in your localhost. 因此,请在您的Web服务器或本地主机中进行尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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