RESUME Download? Direct Link?
I wrote this code for uploading files to my host.For example I upload a file from Server A to Server B and after that I want to download it by my PC, But when I want to download it, for example via IDM, it is not support RESUME download.
Attention : I upload this code to Server B !
<?php
require('config.php');
function is_valid_url($link)
{
$link = @parse_url($link);
if ( ! $link) {
return false;
}
$link = array_map('trim', $link);
$link['port'] = (!isset($link['port'])) ? 80 : (int)$link['port'];
$path = (isset($link['path'])) ? $link['path'] : '';
if ($path == '')
{
$path = '/';
}
$path .= ( isset ( $link['query'] ) ) ? "?$link[query]" : '';
if ( isset ( $link['host'] ) AND $link['host'] != gethostbyname ( $link['host'] ) )
{
if ( PHP_VERSION >= 5 )
{
$headers = get_headers("$link[scheme]://$link[host]:$link[port]$path");
}
else
{
$fp = fsockopen($link['host'], $link['port'], $errno, $errstr, 30);
if ( ! $fp )
{
return false;
}
fputs($fp, "HEAD $path HTTP/1.1\r\nHost: $link[host]\r\n\r\n");
$headers = fread ( $fp, 128 );
fclose ( $fp );
}
$headers = ( is_array ( $headers ) ) ? implode ( "\n", $headers ) : $headers;
return ( bool ) preg_match ( '#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers );
}
return false;
}
if (isset($_POST['pass']) && isset($_POST['user'])){
if ($_POST['pass'] == $pass && $_POST['user'] == $user){
if (!$pass | !$user | !$sa开发者_如何学运维ve | !$link){
include('./error.php');
}elseif(is_valid_url($link) && copy($link, $upload_folder.'/'.$save)){
include('./index.2.php');
}else{
include('./error.php');
}
}else{
include('./error.php');
}
}
?>
Thanks for your help ...
I can't make heads or tails out of this code. Do you want to download a file from the server this script runs on? If so what's with that HEAD request? Or do you want to run this script on server A and download from server B? Very confusing. If you want to deal with a HTTP_RANGE header, Parsing HTTP_RANGE header in PHP
精彩评论