H
H
hesy2020-05-20 21:51:49
PHP
hesy, 2020-05-20 21:51:49

How to send a file to the browser for download?

There is a link to the video: https: //api2.musical.ly/aweme/v1/playwm/ ?video_id = ... I have the following file with this code:


download.php
<?php

if (isset($_GET['video']))
{
    $ch = curl_init($_GET['video']);

    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1)
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);

    curl_close($ch);

    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=video.mp4");
    echo $output;

    die();
}


I am trying to download a file like this:
https://example.com/download.php?video=https://api2.musical.ly/aweme/v1/playwm/?video_id=v09044530000bqsiqd8lths38b053nrg


A broken file with a weight of 1kb is downloaded, but if you pass it the final link that after the redirect, the file is saved correctly.

The question is how to display a dialog box prompting you to save the file when you click on the link?
It seems FOLLOWLOCATION indicated, but I don’t understand what the problem is.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-05-20
@hesy

Write User-Agent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question