简体   繁体   English

从HTTPS网址PHP下载文件

[英]Download files from HTTPS url PHP

I am writing PHP Script for downloading files from wetransfer ( Wetransfer ) 我正在编写PHP脚本,用于从wetransfer下载文件( Wetransfer

i have got php script php script to download from wetransfer 我有php脚本php脚本可从wetransfer下载

The above is great but it has some issues that -- 上面的方法很棒,但是存在一些问题-

  1. we need to provide "output" file ( like "filename.zip") , HOW we come to know that which type of file we are downloading. 我们需要提供“输出”文件(例如“ filename.zip”),如何知道要下载的文件类型。

  2. will the script also work for file having GB of size.? 该脚本也可以用于GB大小的文件吗?

one more thing that wetransfer provides short link , i am able to convert that short link into long url , this long url is used in the above code. wetransfer提供的另一件事是短链接,我能够将其转换为长网址,以上代码中使用了长网址。

any help. 任何帮助。

  1. After you download file you can check MIME type with mime_content_type() 下载文件后,您可以使用mime_content_type()检查MIME类型。

  2. It depends on server settings. 这取决于服务器设置。 Also remember that php has so timeout. 还记得php有这么超时。 Maybe it would be better if you use some kind of queue to do it asynchronously. 如果您使用某种队列异步执行它,可能会更好。

  3. It would be better to use readfile() instead of fread() , readfile() won't cause memory problems. 最好使用readfile()而不是fread()readfile()不会引起内存问题。
  4. It is important to turn off output buffering when downloading large files. 下载大文件时,关闭输出缓冲很重要。

Note: readfile() will not present any memory issues, even when sending large files, on its own. 注意:即使单独发送大文件,readfile()也不会出现任何内存问题。 If you encounter an out of memory error ensure that output buffering is off with ob_get_level(). 如果遇到内存不足错误,请确保使用ob_get_level()关闭输出缓冲。

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

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