arrays - How to download multiple PDF links automatically using php and store it in my root folder
Get the solution ↓↓↓I am new to the PHP DOM, I need to know the multiple pdf files downloaded using PHP and stored in my local root folder.
give me the suggestions with the jquery or Ajax method also.
<?php
$htmlinput = <<<EOT
<ul class="property_quicklinks">
<li><a href="https://www.uklandandfarms.co.uk/find-a-mortgage/index.aspx?PropertyRef=kObCgeoo">
<img src="https://www.uklandandfarms.co.uk/media/icons/ico_home.gif" alt="Find a mortgage for this property">
Find a mortgage for this property</a></li>
<li><a href="https://www.uklandandfarms.co.uk/search/brochure.aspx?PropertyRef=kObCgeoo" onclick="popUp(this.href,"elastic",450,550);return false;" rel="external"><img src="/media/icons/ico_document.gif" alt="View a brochure"> View a brochure</a></li>
<li><a href="https://www.uklandandfarms.co.uk/search/brochure.aspx?PropertyRef=26208_STR190165" onclick="popUp(this.href,"elastic",450,650);return false;" rel="external" title="View map (opens in a new window)"><img src="/media/map.gif" alt="View map" class="am"> View map</a></li>
<li><a href="https://www.uklandandfarms.co.uk/search/arrangeaviewing.aspx?PropertyRef=kObCgeoo">
<img src="https://www.uklandandfarms.co.uk/media/icons/ico_key.gif" alt="Contact agent">
Contact agent</a></li>
<li><a href="https://www.uklandandfarms.co.uk/customers/saveproperty.aspx?PropertyRef=kObCgeoo&frm=dt"><img src="/media/icons/ico_addnewaccount.gif" alt="Add to my property portfolio"> Add to my property portfolio</a></li>
<li><a href="https://www.uklandandfarms.co.uk/emailafriend/index.aspx?Ref=UKLF&PropertyRef=kObCgeoo">
<img src="https://www.uklandandfarms.co.uk/media/icons/ico_email.gif" alt="E-mail a friend">
E-mail a friend</a></li>
<li><a href="https://www.uklandandfarms.co.uk/search/detailsprinter.aspx?PropertyRef=kObCgeoo" onclick="popUp(this.href,'elastic',450,550);return false;" rel="external">
<img src="https://www.uklandandfarms.co.uk/media/icons/ico_print.gif" alt="Printer friendly page">
Printer friendly page</a></li>
</ul>
EOT;
$doc = new \DOMDocument();
$doc->loadHTML($htmlinput);
$links = [];
$arr = $doc->getElementsByTagName("a");
foreach($arr as $item) {
$href = $item->getAttribute("href");
$text = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
$links[] = [
'href' => $href,
'text' => $text
];
}
?>
<a id="load_URL" target="_blank" class="download_file" href="<?php echo $links[1][href]; ?>" download="<?php echo $links[1][href]; ?>">Download PDF</a>
<a id="load_URL" target="_blank" class="download_file" href="<?php echo $links[2][href]; ?>" download="<?php echo $links[2][href]; ?>">Download PDF</a>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: deprecated: directive 'allow_url_include' is deprecated in unknown on line 0
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.