F
F
FANTASANTA2020-04-25 21:27:06
PHP
FANTASANTA, 2020-04-25 21:27:06

How to download a file from a link to a computer?

I am using the file_put_contents() and fopen() functions.

file_put_contents("test.mp4", fopen('https://site.com/file.mp4', 'r'));

But the file is uploading to my FTP (to the site itself). I need to download this file to my computer. How to do?

UPD: Found this kind of solution, but it doesn't work!
if (file_exists($request['url'])) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.$request['url'].'"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($request['url']));
        readfile($request['url']);
        exit;
      }


$request['url'] - sends a direct link to a video file from vimeo and youtube.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alekssamos, 2020-04-25
@alekssamos

header('Location: https://site.com/file.mp4');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question