i am trying to save pages as html document to my host and open it by PHP & download some links ( e.g http://test.com/.1.mp3& http://test.com/2.apk) 到我自己的主人。 一切都很好,除了我想要在变量中放置标签的 href 属性。
我使用通过curl下载链接的功能。当我直接插入下载链接它工作正常,但在我的代码中,href进入一个没有“”的变量 并卷曲下载一个0kb文件。
在这里你可以看到代码和我的解释。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
include ("simple_html_dom.php"); // sourceforge html dom
$host= " "; // no need
$target = "http://example.com/?p=17977"; // target page
// to save page as html
function gethtm($urlm) {
$url = $urlm;
$time = time() + rand();
$patha = 'html/temp-html.html';
$fp = fopen($patha, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
}
// download the link
function downloadurl ($urlf) {
$url = $urlf;
$path = 'file/temp.apk';
$ch = curl_init($url);
if($ch === false)
{
die('Failed to create curl handle');
}
$fp = fopen($path, 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
curl_close($ch);
fclose($fp);
}
// save trget
gethtm($target);
// find download link
$html = file_get_html('html/temp-html.html');
foreach($html->find('a') as $element ) {
if( strpos($element->href , 'http://dl2.packdl') !== false) {
$linka = $element->href;
}
}
echo $linka;
/* here is where u can see my problem if i insert download link myself it
download it and works
but does not work by $linka !
i tried this values ----> $linka '"'.$linka.'"' "'".$linka."'" '.$linka.'
also tried this values inside of function but everytime it return 0kb file
but if i insert download link : "http://example.com/file.rar"
it works and download file ...
that's my question how to download link inside $linka ?
*/
downloadurl('"'.$linka.'"');
?>
</body>
</html>
这是我的问题如何在$ linka中下载链接?