Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question