PHP Dateidownload Klasse

S

spex

Moin,

folgendes Script hab ich geschrieben.
PHP:
<?php
/*COPYRIGHT*/
  
class DATABASE
{

	var $server;
	var $port;
	var $username;
	var $password;
	var $debug;
	var $database;
	var $prefix;
	var $result;
	var $db;
	var $db_handle;
	
	var $error;
	var $errno;

	// //////////////////////////////
	// Constructor
	function DATABASE($server, $username, $password, $database, $port = 3306, $prefix = "", $pconnect = 0,  $debug = 0)
	{
	
		$this->server		=		$server;
		$this->port			=		$port;
		$this->username		=		$username;
		$this->password		=		$password;
		$this->database		=		$database;
		$this->prefix		=		$prefix;
		$this->debug		=		$debug;
		
		if($pconnect)
		{
			// Use a persistante connection
			$this->db_handle = @mysql_pconnect($server.':'.$port, $username, $password, true);
		}
		else
		{
			// Simple connection
			$this->db_handle = @mysql_connect ($server.':'.$port, $username, $password, true);
		}
		
		// Select Database
		$this->db = @mysql_select_db($database, $this->db_handle);
		
		// Error Handling
		$this->debug();
		
	return 1;
	}
	
		// //////////////////////////////
		// Functions
		
		// //////////////////////////////
		function debug($query = "")
		{

			if($this->debug && (!$this->db || ($query <> "" && !$this->result)))
			{
				$this->error = mysql_error();
				$this->errno = mysql_errno();
		
				print("Error: $this->error<br >\nErrno: $this->errno<br />\n");

                                if($query <> "")
                                {
                                    print("Query: $query");
                                }
				
			exit;
			}
			else
			{
			return 1;
			}
		}
		
		// //////////////////////////////
		function query($query)
		{
			$this->result = mysql_query($query, $this->db_handle);
			
		return $this->debug($query);
		}

};

?>

Aufruf:
PHP:
<?php

require_once('class_download.php');

	$DL = &new DOWNLOAD('bin/test.tar', 'lalala.tar', 25, 1);
	$DL->start();

?>

Hier bekomme ich immer folgenden Fehler:
Code:
Parse error: syntax error, unexpected ')' in /var/www/example.com/htdocs/dls/class_download.php on line 28
Ich kann mir den Fehler nicht erklären, die Klammern müssen quasie richtig geschlossen sein. Ich fang langsam an an mir selbst zu zweifeln...

Danke für eure Hilfe - Gruss
 
Zuletzt bearbeitet von einem Moderator:
Danke für die durchaus schnelle Antwort.
Es geht nur irgendwie sind die Fehlermeldungen etwas in der Zeile verschoben.

Wie auch immer, noch ist irgendwo ein Bug drinne. Ich such ihn mal und poste dann das korrekte Script nochmal.

Gruss


//EDIT:
Hier das korrekte Script:
PHP:
<?php
/*COPYRIGHT*/

class DOWNLOAD
{

// //////////////////////////////
// Variables
var 	$MYSQL_DB	= NULL;	// Valid Linkresource to MySQL-Database
var 	$MYSQL_TBL	= NULL;	// Table of currently selected Database
var 	$MYSQL_COL_PUT;		// Column that consits komplete generated traffic
var 	$MYSQL_COL_GET;		// Column that consits komplete allowed traffic
var		$MYSQL_LIVE_UPDATE; // Updates State live and not only on finished Downloads
var		$RESULT		= 0;	// Result of Filedownload
private	$FILE;				// Path to the file
private $FILE_NAME;			// Name in "Save As:" dialoge
private	$MAX_SPEED;			// Speedlimit in KByte/s
private	$RESUMABLE;			// Pausable & resumable
private	$RANGE		= 0;	// Requested fileseek
private	$SIZE;				// Filesize in Bytes
private	$STATE		= 0;	// Current State in Bytes
private $BLOCK_SIZE = 1024;	// Blocksize of fgets()
private $BROWSER;			// Client-Browser

	// //////////////////////////////
	// Constructor
	function DOWNLOAD($file, $file_name = NULL, $max_speed = NULL, $resumable = 1) {
	
		if(file_exists($file) && is_readable($file)) {
		
			// Set standart Variables
			$this->FILE			=	$file;
			$this->MAX_SPEED	=	$max_speed;
			$this->RESUMABLE	=	$resumable;
			
			// Set filename in "Save As:"
			if($file_name == '')
				$this->FILE_NAME = rawurldecode(basename($file));
			else
				$this->FILE_NAME = rawurldecode($file_name);
				
			// Get Client-Browser
			if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']))
				$this->BROWSER = "Opera";
			elseif (ereg('MSIE ([0-9].[0-9]{1,2})',  $_SERVER['HTTP_USER_AGENT']))
				$this->BROWSER = "IE";
			else
				$this->BROWSER = '';
				
			// Get Filedata (Size...)
			$this->SIZE = filesize($this->FILE);
			$mime_type	= ($this->BROWSER == 'IE' || $this->BROWSER == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
			
			// Set Headers
			header("Content-Type: $mime_type");
			header("Content-Disposition: attachment; filename=\"{$this->FILE_NAME}\"");
			header("Expires: $expires");
			header("Accept-Ranges: bytes");
			header("Cache-control: private");
			header('Pragma: private');
			
			// Set Blocksize if Speedlimit is enabled
			if($this->MAX_SPEED > 0)
               $this->BLOCK_SIZE *= $this->MAX_SPEED;
			
			// Set Range if Resumable
			if($this->RESUMABLE && isset($_SERVER['HTTP_RANGE'])) {
				if(preg_match("/bytes=(.*)-/", $_SERVER['HTTP_RANGE'], $this->RANGE)) {
					$this->RANGE = $this->RANGE[1];

					header("HTTP/1.1 206 Partial Content");
					header("Content-Length: ".($this->SIZE - $this->RANGE));
					header("Content-Range: bytes ".$this->RANGE."-".($this->SIZE - 1)."/{$this->SIZE}");					
				} else {
					header("Content-Length: {$this->SIZE}");
				}
			} else {
				header("Content-Length: {$this->SIZE}");
			}

		} else
			die('File not found or not readable!'); // Error: File not found!
		
	}
	
// //////////////////////////////
// Methods

// Starts the download
function start() {
	$FILE = fopen($this->FILE, 'r'); // Create Filehandle
	fseek($FILE, $this->RANGE);
	
		//@ob_end_clean();
		
		while(!feof($FILE)) {
		
			print(fread($FILE, $this->BLOCK_SIZE)); // Get data
			flush();								// Wirte out buffer
			
			// Set Status
			$this->STATE = ftell($FILE);
			
			// Wait if Speedlimit is enabled
			if($this->MAX_SPEED > 0)
				sleep(1);
		}
	fclose($FILE);
}

};

?>
 
Zuletzt bearbeitet von einem Moderator:
Zurück