[php]
<title>Remote Download Script</title>
<style type="text/css">
body {background: black; color: white;}
a:link {color: #CCFFFF}
a:visited {color: #FFFFFF}
a:hover {color: #99FFFF}
a:active {color: #66FFFF}
</style>
<center><h1>Remote Download Script</h1></center>
<form method="post" enctype="multipart/form-data">
Remote File: <input type="text" name="url"><br>
Local File: <input type="text" name="output">
<input type="submit" value="Download"><br>
<?php
function human_file_size($size) {
$filesizename = array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i];
}
function duration($int_seconds=0, $if_reached=null) {
$key_suffix = ’s‘;
$periods = array(‚year’=>31556926,’month’=>2629743,’day’=>86400,’hour’=>3600,’minute’=>60,’second’=>1);
$flag_hide_zero = true;
foreach( $periods as $key => $length )
{
$temp = floor( $int_seconds / $length );
if( !$flag_hide_zero || $temp > 0 )
{
$build[] = $temp.‘ ‚.$key.($temp!=1?’s‘:null);
$flag_hide_zero = false;
}
$int_seconds = fmod($int_seconds, $length);
}
return ( !empty($build)?implode(‚, ‚, $build):$if_reached );
}
if(!is_writeable(‚./‘)) {
exit(‚Cannot write to local dir (needs chmod).‘);
}
$remote_file = $_POST[‚url‘];
if($_POST[‚output‘]) {
$local_file = $_POST[‚output‘];
} else {
$decoded_url = rawurldecode($remote_file);
$local_file = substr($decoded_url, strrpos($decoded_url, ‚/‘) + 1);
}
if(file_exists($local_file)) {
unlink($local_file);
echo("<b>$local_file</b> has Been Replaced<br>");
}
if($remote_file) {
$startTime = time();
set_time_limit(0);
ignore_user_abort();
$file_in = fopen($remote_file, ‚r‘);
$file_out = fopen(‚./‘.$local_file, ‚a‘);
if($file_in) {
while(!feof($file_in)) {
$buffer = fread($file_in, 8192);
fwrite($file_out, $buffer, 8192);
}
fclose($file_in);
fclose($file_out);
$size = filesize($local_file);
$humansize = human_file_size($size);
$seconds = time() – $startTime;
if($size <= 10240) {
unlink($local_file);
exit("<b>$local_file</b> has been deleted");
}
$count = duration($seconds);
$url = rawurlencode($local_file);
exit("<b>Filename: </b><a href=$url>$local_file</a><br><b>Filesize: </b>$humansize<br><b>Time: </b>$count");
}
}
exit;
?>
</form>
[/php]