-1

I am trying to download pdf file from this url:

http://knihy.cpress.cz/?p=actions&action=download/file&value=files&id=149253

I tried get file through file_get_contents, but it downloaded just php file without actual pdf.

Is there a way to download this file?

Thank you very much!

Peon
  • 7,902
  • 7
  • 59
  • 100
midz
  • 65
  • 7
  • This is not a problem, but rather a hacking try – Peon Jun 22 '17 at 08:14
  • Please remember that we cannot read you mind. What do you need to do, how are you doing it and how does it fails to meet your expectations? Is this a programming question for your web site, or you're just trying to grab contents from some other place? – Álvaro González Jun 22 '17 at 08:17
  • Thank you for responses. I am trying to download this pdf file and save it in folder on my server. – midz Jun 22 '17 at 08:22

1 Answers1

1
<?php

    function collect_file($url){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, false);
        curl_setopt($ch, CURLOPT_REFERER, "http://www.xcontest.org");
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $result = curl_exec($ch);
        curl_close($ch);
        return($result);
    }

    function write_to_file($text,$new_filename){
        $fp = fopen($new_filename, 'w');
        fwrite($fp, $text);
        fclose($fp);
    }


    // start loop here

    $new_file_name = "testfile.pdf";
    $url = "http://knihy.cpress.cz/?p=actions&action=download/file&value=files&id=149253";

    $temp_file_contents = collect_file($url);
    write_to_file($temp_file_contents,$new_file_name)

    // end loop here
?>

from here

to.shi
  • 94
  • 3