0

I want download this file

http://193.111.141.206:8000/live/mirko/mirko/22.m3u8

and want to save on server.

I have this php script:

<?php
$ts1 = http://193.111.141.206:8000/live/mirko/mirko/22.m3u8;
file_put_contents("stream.m3u8", fopen($ts1, 'r'));
?>

I get this error

Warning: fopen( http://193.111.141.206:8000/live/mirko/mirko/22.m3u8): failed to open stream: Connection timed out in /home/.../download.php on line 25

Manualy I can open this file, but php says Connection timed out... Anybody know a solution?

Aleksandar
  • 501
  • 3
  • 10
  • 21
  • 3
    `file_put_contents` expects a string for its input. you're passing in a file handle, which will never work. you need `file_put_contents(.., file_get_contents(...))`. and since the connection times out anyways, you need to investigate why. either the remote site is blocking your server, or your server's firewall is preventing apache/php from opening network connections. – Marc B May 26 '16 at 20:44
  • @strangeqargo: uh, what uploads? ignoring all the other problems, OP is trying to download that url into a local .m3u8 file. – Marc B May 26 '16 at 20:45
  • The code you have shown here will not parse (there are no quotes around the URL). The other line is semantically incorrect. – symcbean May 26 '16 at 20:45
  • I think you need to use [file_get_contents](http://php.net/manual/en/function.file-get-contents.php) before calling `file_put_contents`. –  May 26 '16 at 20:47
  • oh, sorry, I somehow got an idea author wants to use file_put_contents to upload file to server. Maybe because of this "download file to server" phrase. Missed this handle thing – strangeqargo May 26 '16 at 20:50
  • I tried `file_get_contents` and `file_put_contents` but Connection timed out.. @MarcB maybe something blocked this function. Can download with another function? – Aleksandar May 26 '16 at 21:11
  • Firewall has been disabled and I have same error – Aleksandar May 26 '16 at 21:17
  • We always used CURL+PHP for this type of work, but, maybe you should look here http://stackoverflow.com/questions/4003989/upload-a-file-using-file-get-contents – strangeqargo May 26 '16 at 22:16
  • Tried curl and same error. How to use wget in php for dowload? – Aleksandar May 26 '16 at 22:38
  • This definitely something internal and it will be hard to diagnose it. For me this `file_get_contents('http://193.111.141.206:8000/live/mirko/mirko/22.m3u8');` works like a charm. – Aleksander Wons May 27 '16 at 10:06
  • @Aleksandar: if f_g_c can't do it, then other functions probably can't either, especially if the problem is somewhere OUTSIDE of your server, e.g. the firewall. – Marc B May 27 '16 at 18:54

1 Answers1

0

Thanks everybody. I do website transfer to another server and file_get_contents, file_put_contents functions works.

P.S.

exec('wget http://google.com/index.html -whateverargumentisusedforoutput', $array);

server saw this code as malware :)

Aleksandar
  • 501
  • 3
  • 10
  • 21