/** * Deletes an Attachment */ function unlink_attach($filename, $mode = false) { global $upload_dir, $config, $lang; $filename = basename($filename); if (!intval($config['allow_ftp_upload'])) { if ($mode == MODE_THUMBNAIL) { $filename = $upload_dir . '/' . THUMB_DIR . '/t_' . $filename; } else { $filename = $upload_dir . '/' . $filename; } $deleted = @unlink($filename); } else { $conn_id = attach_init_ftp($mode); if ($mode == MODE_THUMBNAIL) { $filename = 't_' . $filename; } $res = @ftp_delete($conn_id, $filename); if (!$res) { if (ATTACH_DEBUG) { $add = $mode == MODE_THUMBNAIL ? '/' . THUMB_DIR : ''; message_die(GENERAL_ERROR, sprintf($lang['Ftp_error_delete'], $config['ftp_path'] . $add)); } return $deleted; } @ftp_quit($conn_id); $deleted = true; } return $deleted; }
/** * FTP File to Location */ function ftp_file($source_file, $dest_file, $mimetype, $disable_error_mode = false) { global $config, $lang, $error, $error_msg; $conn_id = attach_init_ftp(); // Binary or Ascii ? $mode = FTP_BINARY; if (preg_match("/text/i", $mimetype) || preg_match("/html/i", $mimetype)) { $mode = FTP_ASCII; } $res = @ftp_put($conn_id, $dest_file, $source_file, $mode); if (!$res && !$disable_error_mode) { $error = true; if (!empty($error_msg)) { $error_msg .= '<br />'; } $error_msg = sprintf($lang['Ftp_error_upload'], $config['ftp_path']) . '<br />'; @ftp_quit($conn_id); return false; } if (!$res) { return false; } @ftp_site($conn_id, 'CHMOD 0644 ' . $dest_file); @ftp_quit($conn_id); return true; }
/** * Check if Attachment exist */ function attachment_exists($filename) { global $upload_dir, $config; $filename = basename($filename); if (!intval($config['allow_ftp_upload'])) { if (!@file_exists(@amod_realpath($upload_dir . '/' . $filename))) { return false; } else { return true; } } else { $found = false; $conn_id = attach_init_ftp(); $file_listing = array(); $file_listing = @ftp_rawlist($conn_id, $filename); for ($i = 0, $size = sizeof($file_listing); $i < $size; $i++) { if (ereg("([-d])[rwxst-]{9}.* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)", $file_listing[$i], $regs)) { if ($regs[1] == 'd') { $dirinfo[0] = 1; // Directory == 1 } $dirinfo[1] = $regs[2]; // Size $dirinfo[2] = $regs[3]; // Date $dirinfo[3] = $regs[4]; // Filename $dirinfo[4] = $regs[5]; // Time } if ($dirinfo[0] != 1 && $dirinfo[4] == $filename) { $found = true; } } @ftp_quit($conn_id); return $found; } }
function send_file_to_browser($attachment, $upload_dir) { global $HTTP_USER_AGENT, $HTTP_SERVER_VARS, $lang, $db, $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; } } // // Determine the Browser the User is using, because of some nasty incompatibilities. // Most of the methods used in this function are from phpMyAdmin. :) // if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) { $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; } else { if (!isset($HTTP_USER_AGENT)) { $HTTP_USER_AGENT = ''; } } if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[2]; $browser_agent = 'opera'; } else { if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'ie'; } else { if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'omniweb'; } else { if (ereg('Netscape([0-9]{1})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'netscape'; } else { if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'mozilla'; } else { if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)) { $browser_version = $log_version[1]; $browser_agent = 'konqueror'; } else { $browser_version = 0; $browser_agent = 'other'; } } } } } } // 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'; } // Now the tricky part... let's dance // @ob_end_clean(); // @ini_set('zlib.output_compression', 'Off'); header('Pragma: public'); // header('Content-Transfer-Encoding: none'); $real_filename = html_entity_decode(basename($attachment['real_filename'])); // Send out the Headers header('Content-Type: ' . $attachment['mimetype'] . '; name="' . $real_filename . '"'); header('Content-Disposition: attachment; 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 { 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_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; }
/** * Returns the filesize of the upload directory in human readable format */ function get_formatted_dirsize() { global $attach_config, $upload_dir, $lang; $upload_dir_size = 0; if (!intval($attach_config['allow_ftp_upload'])) { if ($dirname = @opendir($upload_dir)) { while ($file = @readdir($dirname)) { if ($file != 'index.php' && $file != '.htaccess' && !is_dir($upload_dir . '/' . $file) && !is_link($upload_dir . '/' . $file)) { $upload_dir_size += @filesize($upload_dir . '/' . $file); } } @closedir($dirname); } else { $upload_dir_size = $lang['Not_available']; return $upload_dir_size; } } else { $conn_id = attach_init_ftp(); $file_listing = array(); $file_listing = @ftp_rawlist($conn_id, ''); if (!$file_listing) { $upload_dir_size = $lang['Not_available']; return $upload_dir_size; } for ($i = 0; $i < count($file_listing); $i++) { if (ereg("([-d])[rwxst-]{9}.* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)", $file_listing[$i], $regs)) { if ($regs[1] == 'd') { $dirinfo[0] = 1; // Directory == 1 } $dirinfo[1] = $regs[2]; // Size $dirinfo[2] = $regs[3]; // Date $dirinfo[3] = $regs[4]; // Filename $dirinfo[4] = $regs[5]; // Time } if ($dirinfo[0] != 1 && $dirinfo[4] != 'index.php' && $dirinfo[4] != '.htaccess') { $upload_dir_size += $dirinfo[1]; } } @ftp_quit($conn_id); } if ($upload_dir_size >= 1048576) { $upload_dir_size = round($upload_dir_size / 1048576 * 100) / 100 . ' ' . $lang['MB']; } else { if ($upload_dir_size >= 1024) { $upload_dir_size = round($upload_dir_size / 1024 * 100) / 100 . ' ' . $lang['KB']; } else { $upload_dir_size = $upload_dir_size . ' ' . $lang['Bytes']; } } return $upload_dir_size; }
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; }
function thumbnail_exists($filename) { global $upload_dir, $attach_config; if (!intval($attach_config['allow_ftp_upload'])) { if (!@file_exists(@amod_realpath($upload_dir . '/' . THUMB_DIR . '/t_' . $filename))) { return FALSE; } else { return TRUE; } } else { $found = FALSE; $conn_id = attach_init_ftp(MODE_THUMBNAIL); $file_listing = array(); $filename = 't_' . $filename; $file_listing = @ftp_rawlist($conn_id, $filename); for ($i = 0; $i < count($file_listing); $i++) { if (ereg("([-d])[rwxst-]{9}.* ([0-9]*) ([a-zA-Z]+[0-9: ]*[0-9]) ([0-9]{2}:[0-9]{2}) (.+)", $file_listing[$i], $regs)) { if ($regs[1] == 'd') { $dirinfo[0] = 1; // Directory == 1 } $dirinfo[1] = $regs[2]; // Size $dirinfo[2] = $regs[3]; // Date $dirinfo[3] = $regs[4]; // Filename $dirinfo[4] = $regs[5]; // Time } if ($dirinfo[0] != 1 && $dirinfo[4] == $filename) { $found = TRUE; } } @ftp_quit($conn_id); return $found; } }