Application->RecallVar('user_id').' AND ProductId = '.$product_id; return $this->Conn->GetOne($sql); } function SendFile($file_id, $product_id) { $file_object = $this->Application->recallObject('file', null, Array('skip_autoload' => true)); /* @var $file_object kDBItem */ $sql = $file_id ? 'SELECT FileId, FilePath, RealPath, MIMEType FROM '.$this->Application->getUnitOption('file', 'TableName').' WHERE FileId = '.$file_id : 'SELECT FileId, FilePath, RealPath, MIMEType FROM '.$this->Application->getUnitOption('file', 'TableName').' WHERE ProductId = '.$product_id.' AND IsPrimary = 1'; $file_info = $this->Conn->GetRow($sql); $field_options = $file_object->GetFieldOptions('RealPath'); $file_info['real_path'] = FULL_PATH.$field_options['upload_dir'].'/'.$file_info['RealPath']; $file_info = $this->DoSendFile($file_info); return $file_info; } function DoSendFile($file_info) { $this->Application->setContentType(kUtil::mimeContentType($file_info['real_path']), false); header('Content-Disposition: attachment; filename="' . $file_info['FilePath'] . '"'); header('Content-Length: ' . filesize($file_info['real_path'])); $file_info['download_start'] = adodb_mktime(); readfile($file_info['real_path']); flush(); $file_info['download_end'] = adodb_mktime(); // this is incorrect define('SKIP_OUT_COMPRESSION', 1); return $file_info; } function LogDownload($product_id, $file_info) { $down_object = $this->Application->recallObject('down', null, Array('skip_autoload' => true)); $user_object = $this->Application->recallObject('u.current'); $product_object = $this->Application->recallObject( 'p' ); $down_object->SetDBField('PortalUserId', $this->Application->RecallVar('user_id')); $down_object->SetDBField('Username', $user_object->GetDBField('Username')); $down_object->SetDBField('ProductId', $product_id); $down_object->SetDBField('ProductName', $product_object->GetField('Name')); $down_object->SetDBField('FileId', $file_info['FileId']); $down_object->SetDBField('Filename', $file_info['FilePath']); $down_object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']); $down_object->SetDBField('StartedOn_date', $file_info['download_start']); $down_object->SetDBField('StartedOn_time', $file_info['download_start']); $down_object->Create(); } }