【问题标题】:PHP: Downloading pdf file without direct link [closed]PHP:下载没有直接链接的pdf文件[关闭]
【发布时间】:2017-06-22 08:13:16
【问题描述】:

我正在尝试从此网址下载 pdf 文件:

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

我尝试通过 file_get_contents 获取文件,但它只下载了没有实际 pdf 的 php 文件。

有没有办法下载这个文件?

非常感谢!

【问题讨论】:

  • 这不是问题,而是黑客尝试
  • 请记住,我们无法读懂您的想法。你需要做什么,你是怎么做的,它怎么没有达到你的期望?这是您网站的编程问题,还是您只是想从其他地方获取内容?
  • 感谢您的回复。我正在尝试下载此 pdf 文件并将其保存在我服务器上的文件夹中。

标签: downloading-website-files


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2012-10-05
    • 2015-12-06
    相关资源
    最近更新 更多