function thumbnail_exists($filename) { global $upload_dir, $attach_config; if (!intval($attach_config['allow_ftp_upload'])) { $found = file_exists(amod_realpath($upload_dir . '/' . THUMB_DIR . '/t_' . $filename)); } else { include_once 'includes/classes/cpg_ftp.php'; $ftp = new cpg_ftp($attach_config['ftp_server'], $attach_config['ftp_user'], $attach_config['ftp_pass'], $attach_config['ftp_path'] . '/' . THUMB_DIR, $attach_config['ftp_pasv_mode']); $found = $ftp->exists($filename); $ftp->close(); } return $found; }
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 { include_once 'includes/classes/cpg_ftp.php'; $ftp = new cpg_ftp($attach_config['ftp_server'], $attach_config['ftp_user'], $attach_config['ftp_pass'], $attach_config['ftp_path'], $attach_config['ftp_pasv_mode']); $file_listing = $ftp->dirlist(); $ftp->close(); if (!$file_listing) { return $lang['Not_available']; } for ($i = 0; $i < count($file_listing); $i++) { if (!$file_listing[1] && $file_listing[4] != 'index.php' && $file_listing[4] != '.htaccess') { $upload_dir_size += $file_listing[1]; } } } return filesize_to_human($upload_dir_size); }
function send_file_to_browser($attachment, $upload_dir) { global $_SERVER, $lang, $db, $attach_config, $board_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. :) // $HTTP_USER_AGENT = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#', $HTTP_USER_AGENT)) { $browser_agent = 'opera'; } else { if (preg_match('#MSIE ([0-9].[0-9]{1,2})#', $HTTP_USER_AGENT)) { $browser_agent = 'ie'; } else { if (preg_match('#OmniWeb/([0-9].[0-9]{1,2})#', $HTTP_USER_AGENT)) { $browser_agent = 'omniweb'; } else { if (preg_match('#Netscape([0-9]{1})#', $HTTP_USER_AGENT)) { $browser_agent = 'netscape'; } else { if (preg_match('#Mozilla/([0-9].[0-9]{1,2})#', $HTTP_USER_AGENT)) { $browser_agent = 'mozilla'; } else { if (preg_match('#Konqueror/([0-9].[0-9]{1,2})#', $HTTP_USER_AGENT)) { $browser_agent = 'konqueror'; } else { $browser_agent = 'other'; } } } } } } if (GZIPSUPPORT) { while (ob_end_clean()) { } header('Content-Encoding: none'); } // Now the tricky part... let's dance /* header('Pragma: public'); header('Content-Transfer-Encoding: none'); header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); */ // // Now send the File Contents to the Browser // if ($gotit) { $size = filesize($filename); if ($attachment['mimetype'] == 'application/x-zip-compressed') { if (intval($attach_config['allow_ftp_upload'])) { if (trim($attach_config['download_path']) == '') { message_die(GENERAL_ERROR, 'Physical Download not possible with the current Attachment Setting'); } $url = trim($attach_config['download_path']) . '/' . $attachment['physical_filename']; $redirect_path = $url; } else { $redirect_path = '/' . $upload_dir . '/' . $attachment['physical_filename']; } URL::redirect($redirect_path); } else { // Correct the mime type - we force application/octetstream for all files, except images // Please do not change this, it is a security precaution if (false === stripos($attachment['mimetype'], 'image')) { $attachment['mimetype'] = $browser_agent == 'ie' || $browser_agent == 'opera' ? 'application/octetstream' : 'application/octet-stream'; } if (!($fp = fopen($filename, 'rb'))) { cpg_error('Could not open file for sending'); } // Send out the Headers header('Content-Type: ' . $attachment['mimetype'] . '; name="' . $attachment['real_filename'] . '"'); header('Content-Disposition: inline; filename="' . $attachment['real_filename'] . '"'); print fread($fp, $size); fclose($fp); } } else { if (!$gotit && intval($attach_config['allow_ftp_upload'])) { $tmp_path = !ini_get('safe_mode') ? '/tmp' : $upload_dir . '/tmp'; $tmp_filename = tempnam($tmp_path, 't0000'); unlink($tmp_filename); include_once 'includes/classes/cpg_ftp.php'; $ftp = new cpg_ftp($attach_config['ftp_server'], $attach_config['ftp_user'], $attach_config['ftp_pass'], $attach_config['ftp_path'], $attach_config['ftp_pasv_mode']); $mode = FTP_BINARY; if (preg_match("/text/i", $attachment['mimetype']) || preg_match("/html/i", $attachment['mimetype'])) { $mode = FTP_ASCII; } $result = ftp_get($ftp->connect_id, $tmp_filename, $filename, $mode); $ftp->close(); 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."); } $size = filesize($tmp_filename); if ($size) { header("Content-length: {$size}"); } if ($attachment['mimetype'] == 'application/x-zip-compressed') { if (intval($attach_config['allow_ftp_upload'])) { if (trim($attach_config['download_path']) == '') { message_die(GENERAL_ERROR, 'Physical Download not possible with the current Attachment Setting'); } $url = trim($attach_config['download_path']) . '/' . $attachment['physical_filename']; $redirect_path = $url; } else { $redirect_path = $upload_dir . '/' . $attachment['physical_filename']; } URL::redirect($redirect_path); } else { // 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'; } // Send out the Headers header('Content-Type: ' . $attachment['mimetype'] . '; name="' . $attachment['real_filename'] . '"'); header('Content-Disposition: inline; filename="' . $attachment['real_filename'] . '"'); print readfile($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; }