I
I
Ichi Nya2012-11-05 20:59:59
PHP
Ichi Nya, 2012-11-05 20:59:59

How to write a PHP script to download a file after a redirect?

There is a site. It gives files like site.ru/do.php?id=123
I want to download a file using php.
Tried:
@fopen($path, "r");
file_get_content($path);
and also via cURL.
When the page opens in the browser, the download of the file starts. When you pick up a file through a script, the html page itself is recorded when opened, the file is downloaded.
As I understand it, the header is being checked, but I passed it as a parameter via cURL, it didn’t work (well, my hands are crooked).
Can someone tell me how to do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
la0, 2012-11-05
@Ichi

Show what went wrong with curl.
Maybe just Follow_location was not set.
If nothing happens, it doesn't happen.
This is the easiest way.

A
Anton, 2012-11-05
@sHinE

The most reliable way is to see / write down what headers the browser gives when visiting the page and downloading, and then send the exact same headers by the script, and it doesn’t matter there already, curl, file_get_contents or even through sockets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question