-1
我想从这个网址下载PDF文件:PHP:下载PDF文件,而无需直接链接
http://knihy.cpress.cz/?p=actions&action=download/file&value=files&id=149253
我试图获取文件的file_get_contents通过,但它只是下载的PHP文件没有实际的PDF文件。
有没有办法可以下载这个文件?
非常感谢!
我想从这个网址下载PDF文件:PHP:下载PDF文件,而无需直接链接
http://knihy.cpress.cz/?p=actions&action=download/file&value=files&id=149253
我试图获取文件的file_get_contents通过,但它只是下载的PHP文件没有实际的PDF文件。
有没有办法可以下载这个文件?
非常感谢!
<?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
?>
谢谢!有用! – midz
这不是一个问题,而是一个黑客尝试 – Peon
请记住,我们无法读取您的想法。你需要做什么,你如何做,以及它如何不能达到你的期望?这是您的网站的编程问题,或者您只是试图从其他地方抓取内容? –
谢谢你的回应。我正在尝试下载此pdf文件并将其保存在我的服务器上的文件夹中。 – midz