function send_file_to_browser($attachment, $upload_dir) { global $bb_cfg, $lang, $userdata; $filename = $upload_dir == '' ? $attachment['physical_filename'] : $upload_dir . '/' . $attachment['physical_filename']; $gotit = false; if (@(!file_exists(@amod_realpath($filename)))) { bb_die($lang['ERROR_NO_ATTACHMENT'] . "<br /><br />" . $filename . "<br /><br />" . $lang['TOR_NOT_FOUND']); } else { $gotit = true; } // Correct the mime type - we force application/octet-stream for all files, except images // Please do not change this, it is a security precaution if (!strstr($attachment['mimetype'], 'image')) { $attachment['mimetype'] = 'application/octet-stream'; } //bt if (!(isset($_GET['original']) && !IS_USER)) { include INC_DIR . 'functions_torrent.php'; send_torrent_with_passkey($filename); } // Now the tricky part... let's dance header('Pragma: public'); $real_filename = clean_filename(basename($attachment['real_filename'])); $mimetype = $attachment['mimetype'] . ';'; $charset = "charset={$bb_cfg['lang'][$userdata['user_lang']]['encoding']};"; // Send out the Headers header("Content-Type: {$mimetype} {$charset} name=\"{$real_filename}\""); header("Content-Disposition: inline; filename=\"{$real_filename}\""); unset($real_filename); // Now send the File Contents to the Browser if ($gotit) { $size = @filesize($filename); if ($size) { header("Content-length: {$size}"); } readfile($filename); } else { bb_die($lang['ERROR_NO_ATTACHMENT'] . "<br /><br />" . $filename . "<br /><br />" . $lang['TOR_NOT_FOUND']); } exit; }
function send_file_to_browser($attachment, $upload_dir) { global $_SERVER, $HTTP_USER_AGENT, $HTTP_SERVER_VARS, $lang, $attach_config; $filename = $upload_dir == '' ? $attachment['physical_filename'] : $upload_dir . '/' . $attachment['physical_filename']; $gotit = FALSE; if (!intval($attach_config['allow_ftp_upload'])) { if (@(!file_exists(@amod_realpath($filename)))) { message_die(GENERAL_ERROR, $lang['Error_no_attachment'] . "<br /><br /><b>404 File Not Found:</b> The File <i>" . $filename . "</i> does not exist."); } else { $gotit = TRUE; } } // Correct the mime type - we force application/octetstream for all files, except images // Please do not change this, it is a security precaution if (!strstr($attachment['mimetype'], 'image')) { $attachment['mimetype'] = $browser_agent == 'ie' || $browser_agent == 'opera' ? 'application/octetstream' : 'application/octet-stream'; } //bt require_once FT_ROOT . 'includes/functions_torrent.php'; send_torrent_with_passkey($filename); //bt end // Now the tricky part... let's dance // @ob_end_clean(); // @ini_set('zlib.output_compression', 'Off'); header('Pragma: public'); // header('Content-Transfer-Encoding: none'); // Send out the Headers header('Content-Type: ' . $attachment['mimetype'] . '; name="' . clean_filename($attachment['real_filename']) . '"'); header('Content-Disposition: inline; filename="' . clean_filename($attachment['real_filename']) . '"'); // // Now send the File Contents to the Browser // if ($gotit) { $size = @filesize($filename); if ($size) { header("Content-length: {$size}"); } readfile($filename); } else { if (!$gotit && intval($attach_config['allow_ftp_upload'])) { $conn_id = attach_init_ftp(); $ini_val = @phpversion() >= '4.0.0' ? 'ini_get' : 'get_cfg_var'; $tmp_path = !@$ini_val('safe_mode') ? '/tmp' : $upload_dir . '/tmp'; $tmp_filename = @tempnam($tmp_path, 't0000'); @unlink($tmp_filename); $mode = FTP_BINARY; if (preg_match("/text/i", $attachment['mimetype']) || preg_match("/html/i", $attachment['mimetype'])) { $mode = FTP_ASCII; } $result = @ftp_get($conn_id, $tmp_filename, $filename, $mode); if (!$result) { message_die(GENERAL_ERROR, $lang['Error_no_attachment'] . "<br /><br /><b>404 File Not Found:</b> The File <i>" . $filename . "</i> does not exist."); } @ftp_quit($conn_id); $size = @filesize($tmp_filename); if ($size) { header("Content-length: {$size}"); } readfile($tmp_filename); @unlink($tmp_filename); } else { message_die(GENERAL_ERROR, $lang['Error_no_attachment'] . "<br /><br /><b>404 File Not Found:</b> The File <i>" . $filename . "</i> does not exist."); } } exit; }