<?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;
我有一个页面,其中包含超过500个剪报信息以及日期,名称,媒体名称和图像路径。 我想使用脚本下载所有这些但我不知道如何编写下载脚本。
这是link
任何帮助都会很棒。
谢谢。
答案 0 :(得分:0)
检查以下功能,该功能无法正常工作,您需要尝试对其进行一些更改。
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);
}
}
答案 1 :(得分: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);
这将帮助您下载第1页的图像和内容。
希望这有帮助。