简体   繁体   English

是否可以通过 javascript 中的链接自动下载文件?

[英]is it possible automatically download a file by the link in javascript?

lets say i have 1000 link like假设我有 1000 个链接

https://test123.sharepoint.com/teams/TechnicalRecordsManagement/Workshop/2014/578090.pdf 

is it possible to make automatic download without user interaction due to security issues???由于安全问题,是否可以在没有用户交互的情况下进行自动下载???

some people says browsers no longer lets you download files without user interaction due to security issues.有人说,由于安全问题,浏览器不再允许您在没有用户交互的情况下下载文件。

i tried simple ways from here Auto download file from a link using javascript我从这里尝试了简单的方法 从使用 javascript 的链接自动下载文件

lets say i have 1000 link like... assuming you want to automate the downloading of such files for your own personal uses, you can do so by file_get_contents() without any reliance on a tag.假设我有 1000 个链接,例如...假设您想自动下载此类文件以供您个人使用,您可以通过 file_get_contents() 来实现,而无需依赖标签。 – GetSet – 获取集

@GetSet yes i have my own personal link, i have way like using curl php – Tri @GetSet 是的,我有自己的个人链接,我喜欢使用 curl php – Tri

@Tri I will post a solution without curl, shortly – GetSet @Tri 我很快就会发布一个没有 curl 的解决方案 – GetSet

@Tri. @Tri。 The following grabs the contents of the remote file and saves it to your local drive.下面抓取远程文件的内容并将其保存到本地驱动器。

    $fileToDownload = "https://dmv.ny.gov/brochure/mv21.pdf";
    $contents = file_get_contents($fileToDownload);
    $f = fopen("mv21.pdf", 'w');
    fwrite($f, $contents);
    fclose($f);

Thats the basic concept.这就是基本概念。

Edited to add context.编辑添加上下文。

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

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