0

我编写了这段代码用于将文件上传到我的主机。例如,我将文件从服务器 A 上传到服务器 B,然后我想通过我的 PC 下载它,但是当我想下载它时,例如通过 IDM,它是不支持 RESUME 下载。

注意:我将此代码上传到服务器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 | !$save | !$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');
    }
}
?>

谢谢你的帮助 ...

4

1 回答 1

1

我无法用这段代码做出正面或反面。您想从运行此脚本的服务器下载文件吗?如果是这样,该 HEAD 请求是什么?还是您想在服务器 A 上运行此脚本并从服务器 B 下载?非常混乱。如果要处理 HTTP_RANGE 标头,请在 PHP 中解析 HTTP_RANGE 标头

于 2011-02-11T20:20:26.233 回答