Ever since I released the blogdrive downloader using WGET sometime an year back, I have also been receiving steadfast requests for a cross-platform version of the same because WGET is a linux tool and Windows PHP can not make use of the same unless you have some tricky combinations of Cygwin and other tools.
Today I got some time and wrote a quick version of the same using native PHP fopen/fwrite for the benefit of users. It uses a simple jquery to do an AJAX request and keeps saving the file onto a subfolder on the server.
There are a lot of scope for improvements to this 5 minute script. A few of them are:
Today I got some time and wrote a quick version of the same using native PHP fopen/fwrite for the benefit of users. It uses a simple jquery to do an AJAX request and keeps saving the file onto a subfolder on the server.
There are a lot of scope for improvements to this 5 minute script. A few of them are:
- Show an informative progress bar for the user.
- Zip the downloaded contents and stream it to the browser. Then optionally delete (cleanup) the downloaded files.
- CAPTCHA security when using this on a hosted platform.
- Use Jquery from a CDN instead of having a local version of the script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (@$_GET["ajax"] == "yes") | |
{ | |
$newdir = realpath("."); | |
$newdir .= "\\dir\\" ; | |
$newdir .= uniqid();///. uniqid()); | |
$url2download = $_POST["txtURL"]; | |
mkdir ($newdir); | |
$postscount = $_POST["txtPostsCount"]; | |
set_time_limit(0); | |
for ($c=0;$c<=$postscount;$c++) | |
{ | |
$url = $url2download . "archive/". $c .".html"; | |
$handle = fopen($url, "r"); | |
$contents = stream_get_contents($handle); | |
fclose ($handle); | |
$handle = fopen ($newdir . "\\" .$c .".html", "w"); | |
fwrite ($handle, $contents); | |
fclose ($handle); | |
} | |
die(); | |
} | |
?> | |
<html> | |
<head> | |
<title>Blogdrive Downloader</title> | |
<Script Src="jquery-1.8.0.min.js" type="text/javascript" language="JavaScript"></Script> | |
</head> | |
<body> | |
<form id="frmPost"> | |
<h3>Blogdrive Downloader</h3> | |
<fieldset> | |
<label for="txtURL">URL</label> | |
<input type="text" name="txtURL" id="txtURL"> | |
<label for="txtPostsCount">Post Count</label> | |
<input type="text" name="txtPostsCount" id="txtPostsCount"> | |
<input type="submit" name="btnDownload" id="btnDownload" value="Download" /> | |
</fieldset> | |
<div id="divServerOutput"></div> | |
<script language="JavaScript"> | |
$(document).ready(function() { | |
$("#btnDownload").click (function () | |
{ | |
$.ajax( | |
{ | |
url:"cpbd.php?ajax=yes", | |
type:"POST", | |
data: $("#frmPost").serialize(), | |
success:function(result) | |
{ | |
alert ("Download Complete"); | |
$("#divServerOutput").html(result); | |
}, | |
error: function (result) | |
{ | |
alert ('fail'+jQuery.parseJSON(result)); | |
$("#divServerOutput").html (result); | |
} | |
}); | |
return (false); | |
}); | |
}); | |
</Script> | |
<div align="center"> | |
© 2012 Lavanya Deepak ('Deepak Vasudevan') | |
</div> | |
</form> | |
</body> | |
</html> |