如何使用延迟了强制下载的PHP下载文件? [英] How to download file Using PHP that has delayed force download?
本文介绍了如何使用延迟了强制下载的PHP下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我处于一种需要从URL下载文件的情况,使用直接文件URL(例如 https://somedomain.com/some-path/somefile.exe
I am at a situation, where I need to download files from the URL, it is easy with the direct file URLs like https://somedomain.com/some-path/somefile.exe
file_put_contents( $save_file_loc, file_get_contents($url_to_download);
但是当您延迟从实际打印HTML的URL强制下载时该怎么办,以及如何区分这些URL?
But what to do when you have delayed force download from the URL which actually prints HTML and how to differentiate those URL?
示例URL: https: //filehippo.com/download_mozilla-firefox-64/post_download/
编辑:在上述url上,文件下载开始使用JS,就像我测试了阻止JS并进行下载一样不能开始。
On above url the file download starts using JS, as I tested with blocking JS and download did not start.
在此先感谢您的帮助。
推荐答案
- 使用
file_get_contents
- 读取URL的html f HTML中的文件。您必须访问该页面并查看源以找到URL。在您的> https://filehippo.com/download_mozilla-firefox-64/post_download/ 在
data-qa-download-url = https://dl5.filehippo.com/367/fb9/ef3863463463b174ae36c8bf09a90145/Firefox_Installer.exe?Expires=1594425587&Signature之间找到= 18ab87cedcf3464363469231db54575665668c4f6& amp; url = https://filehippo.com/download_mozilla-firefox-64/& amp; Filename = Firefox_Installer.exe"
- As您可能已经注意到,该页面可能已经预先批准了请求,因此如果主机使用Cookie或其他方法进行检查,则不能保证该页面可以正常工作。
- 基于上述内容创建一个正则表达式以使用
preg_match
- 提取URL,然后file_get_contents下载文件的URL。
- Read the html of the URL using
file_get_contents
- Find the URL of the file within the HTML. You'll have to visit the page and view source to locate the URL. In your example of https://filehippo.com/download_mozilla-firefox-64/post_download/ it's found in between
data-qa-download-url="https://dl5.filehippo.com/367/fb9/ef3863463463b174ae36c8bf09a90145/Firefox_Installer.exe?Expires=1594425587&Signature=18ab87cedcf3464363469231db54575665668c4f6&url=https://filehippo.com/download_mozilla-firefox-64/&Filename=Firefox_Installer.exe"
- As you may have noticed, the page may have pre-approved the request so it's not guaranteed to work if the host has checks using cookies or other methods.
- Create a regex based on the above to extract the URL using
preg_match
- Then file_get_contents the URL of the file to download it.
这篇关于如何使用延迟了强制下载的PHP下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文