Jag håller för första gången på att jobba med klasser och har hackat upp mig när det gäller att skapa object som egenskaper i klassen.
Fölande klass:
class NBDownload
{
//Properties:
var $file_id;
var $path;
var $file;
var $db;
var $session;
//Constructor:
function NBDownload($id) {
$this->file_id = $id;
$this->path = $this->GetPath();
ereg('([^\\/]*)$',$this->path,$regs);
$this->file = $regs[1];
$this->db = new DB_Object;
$this->session = new NBSession;
}
//Methods:
function DownloadFile() {
if(!$fp = @fopen($this->path, 'r')) {
return false;
} else {
//Http headers:
header("Content-disposition: filename=".$this->file);
header('Content-type: application/octetstream');
header('Pragma: no-cache');
header('Expires: 0');
//Send the file:
fpassthru($fp);
fclose($fp);
return true;
}
}
function GetPath() {
global $config;
$this->db->query("SELECT filename FROM downloads_tab WHERE file_id='$file_id'");
$this->db->next_record();
return $config['download_dir'].$this->db->f('filename');
}
function IsDownloadOk() {
//???: Database check. (Compare user_id with file_id.)
return true;
}
}
Ger följande fel när jag använder det:
Fatal error: Call to a member function on a non-object in components\NBDownload.php on line 65
DVS denna rad:
$this->db->query("SELECT filename FROM downloads_tab WHERE file_id='$file_id'");
Skulle vara bra om någon kunde hjälpa mig! tack!
/Nisse