FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Bug Reports » Download a large file with the admin panel (adm/admbrowse.php file download problem)
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Download a large file with the admin panel [message #165475 is a reply to message #164888] Sat, 25 June 2011 13:44 Go to previous messageGo to previous message
Atomicrun is currently offline  Atomicrun   Sweden
Messages: 54
Registered: November 2010
Location: Lund
Karma:
Member
I would like to inquire, what code is used when attachments are downloaded. I typically have many and large attachments, as forum is used to store information, and I would like to use this provided function.
A clue, where it is, would be appreciated.


No, it is not good. The following code comes from www.php.net:

Function, add it in:
function dl_file_resume( $file)
{
   //First, see if the file exists
   if ( ! is_file( $file)) 
   { 
      die( "<b>404 File not found!</b>"); 
   }

   //Gather relevent info about file
   $len = filesize($file);
   $filename = basename($file);
   $file_extension = strtolower(substr(strrchr($filename,"."),1));

   //This will set the Content-Type to the appropriate setting for the file
   switch( $file_extension)
   {
       case "asf":     $ctype = "video/x-ms-asf";                break;
       case "avi":     $ctype = "video/x-msvideo";               break;
       case "exe":     $ctype = "application/octet-stream";      break;
       case "mov":     $ctype = "video/quicktime";               break;
       case "mp3":     $ctype = "audio/mpeg";                    break;
       case "mpg":     $ctype = "video/mpeg";                    break;
       case "mpeg":    $ctype = "video/mpeg";                    break;
       case "rar":     $ctype = "encoding/x-compress";           break;
       case "txt":     $ctype = "text/plain";                    break;
       case "wav":     $ctype = "audio/wav";                     break;
       case "wma":     $ctype = "audio/x-ms-wma";                break;
       case "wmv":     $ctype = "video/x-ms-wmv";                break;
       case "zip":     $ctype = "application/x-zip-compressed";  break;
       case "gz":      $ctype = "application/x-gzip-compressed"; break;
       default:        $ctype = "application/force-download";    break;
   }
   
    //Begin writing headers
    header("Cache-Control:");
    header("Cache-Control: public");
   
    //Use the switch-generated Content-Type
    header("Content-Type: $ctype");
    if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
        # workaround for IE filename bug with multiple periods / multiple dots in filename
        # that adds square brackets to filename - eg. setup.abc.exe becomes setup[1].abc.exe
        $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");
   
    $size=filesize($file);
    //check if http_range is sent by browser (or download manager)
    if(isset($_SERVER['HTTP_RANGE'])) {
        list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
        //if yes, download missing part
        str_replace($range, "-", $range);
        $size2=$size-1;
        $new_length=$size2-$range;
        header("HTTP/1.1 206 Partial Content");
        header("Content-Length: $new_length");
        header("Content-Range: bytes $range$size2/$size");
    } else {
        $size2=$size-1;
        header("Content-Range: bytes 0-$size2/$size");
        header("Content-Length: ".$size);
    }
    // open the file
    $fp = fopen( "$file", "rb");
    
    if ( $fp)
    {
       // seek to start of missing part
       fseek( $fp, $range);
       
       //start buffered download
       while( ! feof( $fp))
       {
           // reset time limit for big files
           set_time_limit( 0);
           print( fread( $fp, 1024*8));
           flush();
           ob_flush();
       }
    }
    fclose( $fp);
}




	/* Download file code. */
	if (isset($_GET['down']) && $dest && @file_exists($cur_dir .'/'. $dest)) {
		if ( is_file($cur_dir .'/'. $dest)) 
		{
			// *** header('Content-type: application/octet-stream');
			// *** header('Content-Disposition: attachment; filename='. $dest);
			// *** header('Content-Length: '. filesize( $cur_dir .'/'. $dest));
			// *** readfile($cur_dir .'/'. $dest);
                  
         dl_file_resume( $cur_dir .'/'. $dest);

		} else {
			header('Content-type: application/x-tar');
			header('Content-Disposition: attachment; filename='. $dest .'.tar');
			echo make_tar($cur_dir .'/'. $dest);
		}
		exit;
	}

	/* Delete file/directory code. */




[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: No such tag: JEI -> $ ban_expiry.
Next Topic: an undefined function ...
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 12:42:15 GMT 2024

Total time taken to generate the page: 0.04468 seconds