shashi sharma
shashi sharma

Reputation: 11

Download files from HTTPS url PHP

I am writing PHP Script for downloading files from wetransfer ( Wetransfer)

i have got php script php script to download from 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.

  2. will the script also work for file having GB of size.?

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.

any help.

Upvotes: 1

Views: 855

Answers (1)

Robert
Robert

Reputation: 20286

  1. After you download file you can check MIME type with mime_content_type()

  2. It depends on server settings. Also remember that php has so timeout. 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.

  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. If you encounter an out of memory error ensure that output buffering is off with ob_get_level().

Upvotes: 1

Related Questions