0

<?php

ignore_user_abort(true);
set_time_limit(0); // disable the time limit for this script

$path = "https://vibrantgujarat.com/pressclippingsnew.htm"; // change the path to fit your websites document structure

$dl_file = preg_replace("([^\w\s\d\-_~,;:\[\]\(\).]|[\.]{2,})", '', $_GET['download_file']); // simple file name validation
$dl_file = filter_var($dl_file, FILTER_SANITIZE_URL); // Remove (more) invalid characters
$fullPath = $path.$dl_file;

if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
            header("Content-type: application/pdf");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a file download
            break;
        // add more headers for other content types here
        default;
            header("Content-type: application/octet-stream");
            header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
            break;
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;

I Have a page which has more than 500 press clippings information along with date, name, media name and image path. I want to download all of them using script but I Don't know how to write download script.

Here is link

Any help would be great.

Thank You.

2 Answers2

0

Checkout the following function, which is not working fully, you need to try out some changes to it.

function saveImageAs(){
 var images = document.getElementsByTagName("img");
 for(var i=0;i<images.length; i++){
  var imgOrURL= images[i].src;
  window.win = open(imgOrURL);
  setTimeout('win.document.execCommand("SaveAs")', 0);
 }
}
Kiran Kumar
  • 1,033
  • 7
  • 20
0

<?php

set_time_limit(0);

//File to save the contents to
$fp = fopen ('download.zip', 'w+');

$url = "https://vibrantgujarat.com/pressclippingsnew.htm";

//Here is the file we are downloading, replace spaces with %20
$ch = curl_init(str_replace(" ","%20",$url));

curl_setopt($ch, CURLOPT_TIMEOUT, 50);

//give curl the file pointer so that it can write to it
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$data = curl_exec($ch);//get curl response

//done
curl_close($ch);

This will help you to download images and contents for the 1st page.

Hope this helps.

Bhavin Shah
  • 2,462
  • 4
  • 22
  • 35