简体   繁体   English

继续下载? 直接链接?

[英]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. 我写了这段代码用于将文件上传到主机,例如,我将文件从服务器A上传到服务器B,然后想要通过PC下载文件,但是当我想通过IDM下载文件时,它是不支持RESUME下载。

Attention : I upload this code to Server B ! 注意:我将此代码上传到服务器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');
    }
}
?>

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? 如果是这样,那HEAD请求又是什么? Or do you want to run this script on server A and download from server B? 还是要在服务器A上运行此脚本并从服务器B下载? Very confusing. 非常混淆。 If you want to deal with a HTTP_RANGE header, Parsing HTTP_RANGE header in PHP 如果要处理HTTP_RANGE标头, 请在PHP中解析HTTP_RANGE标头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM