fork download
  1. <?php
  2. /**
  3. * Downloads the publicly accessible videos.
  4. * This is just a basic demo, can be improved with proper file handling.
  5. *
  6. * @param string $video_url Video URL.
  7. * @param string $referer Referer site.
  8. */
  9.  
  10. function download_video( $video_url, $referer ) {
  11.  
  12. $video_name = basename( $video_url );
  13. $video_path = '/' . $video_name; // Path to downloads folder.
  14.  
  15. try {
  16. $ch = curl_init($video_url);
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  18. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  19. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  20. 'Origin: ' . $referer,
  21. 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
  22. ]);
  23. curl_setopt($ch, CURLOPT_REFERER, $referer);
  24. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  25.  
  26. $video = curl_exec($ch);
  27. if (curl_errno($ch)) {
  28. throw new Exception('Error: ' . curl_error($ch));
  29. } else {
  30. $file = fopen($video_path, 'w');
  31. if ($file === false) {
  32. throw new Exception('Failed to open file for writing.');
  33. }
  34. fwrite($file, $video);
  35. fclose($file);
  36. echo "Video downloaded successfully.";
  37. }
  38. curl_close($ch);
  39. } catch (Exception $e) {
  40. echo $e->getMessage();
  41. }
  42. }
  43.  
  44. /**
  45. * How to use it?
  46. */
  47.  
  48. download_video( 'https://c...content-available-to-author-only...y.com/video/2022/11/22/140111-774507949_large.mp4', 'https://p...content-available-to-author-only...y.com/' );
  49.  
Success #stdin #stdout 0.04s 26404KB
stdin
Standard input is empty
stdout
Error: Could not resolve host: cdn.pixabay.com