V
V
Vladimir Tyutimov2016-01-04 20:45:38
PHP
Vladimir Tyutimov, 2016-01-04 20:45:38

How to download a video from a link to the server?

Hello.
I'm trying to write a script that downloads a file from a link to a server.
link of the form: yuorname.ru/uriffjvy.mp4
Wrote the following code, it creates a file with the name, but does not load the video, the file size is 0 bytes. What am I doing wrong?

set_time_limit(0);

$url = urldecode($_GET['linkv']);
$pi = pathinfo($url);
$ext = $pi['extension'];
$name = $pi['filename'];
$origFileName = $name.'.'.$ext;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$st = curl_exec($ch);
$fd = @fopen($origFileName, 'w');
fwrite($fd, $st);
@fclose($fd);

curl_close($ch);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kalinin, 2016-01-04
@kal1sha

Try file_put_contents

file_put_contents("uriffjvy.mp4", fopen("yuorname.ru/uriffjvy.mp4", 'r'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question