Problems with PHP file upload script (1 file)

Discussion in 'PHP' started by Barti1987, Apr 17, 2007.

  1. #1
    Script:
    * File download that supports file download resuming

    Problem in:
    * Internet Download manager

    Problem:
    * Keeps getting stuck at 99%, constant refresh

    Misc. Info:
    * File is actually there, if task is stopped, view hidden files, the file exist and is complete.

    What is wrong?
    * I think its something with invalid length being sent, I tried to debug with no luck.

    Code:
    
    $file_loc = '/home/files/'.$file_name_is;
    $len = @filesize($file_loc);
    
    $file_info['swf'] = array($directory_link,'application/x-shockwave-flash');
    //*** List keeps going on ****//
    
    $filename = $file_name_show;
    $filename = str_replace(' ','_',$filename);
    
    $file_ext = explode('.',$filename);
    $file_extension = $file_ext[count($file_ext)-1];
    $ctype = $file_info[$file_extension][1];
    
    header("Cache-Control:");
    header("Cache-Control: public");
    header("Content-Type: $ctype");
    
    if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
        $iefilename = preg_replace('/\./', '%2e', $filename, substr_count($filename, '.') - 1);
        header("Content-Disposition: attachment; filename=\"$iefilename\"");
    } else {
        header("Content-Disposition: attachment; filename=\"$filename\"");
    }
    
    header("Accept-Ranges: bytes");
        
    if(isset($_SERVER['HTTP_RANGE'])) {
        list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
        str_replace($range, "-", $range);
        $size2 = $len-1;
        $new_length = $size2-$range;
        header("HTTP/1.1 206 Partial Content");
        header("Content-Length: $new_length");
        header("Content-Range: bytes $range$size2/$len");
    } else {
        $size2=$size-1;
        header("Content-Range: bytes 0-$size2/$size");
        header("Content-Length: ".$len);
    }
    
    $fp = fopen("$file_loc","rb");
    fseek($fp,$range);
    
    
    //start buffered download
    while(!feof($fp)){
        //reset time limit for big files
        set_time_limit(0);
        print(fread($fp,1024*$speed));
        flush();
        ob_flush();
    }
    fclose($fp);
    exit;
    
    
    
    PHP:
    * Will give reps is solved as a sign of appreciation.

    Thanks,
     
    Barti1987, Apr 17, 2007 IP
  2. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Subikar, Apr 17, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Barti1987, Apr 18, 2007 IP
  4. Chamaro Zwinkels

    Chamaro Zwinkels Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This maybe?
    www. phphulp .nl/php/scripts/1/493/
    Sorry, it's dutch (but php ;))
     
    Chamaro Zwinkels, Apr 18, 2007 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    That is an incomplete Image Upload tutorial.

    My question was about an file resume download script.

    Thanks for trying anyway,

    Peace,
     
    Barti1987, Apr 18, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    nico_swd, Apr 18, 2007 IP
  7. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Barti1987, Apr 18, 2007 IP