| view.php |
|
1 <?php
2 /* 3 +----------------------------------------------------------------+ 4 | | 5 | GaMerZ File Explorer Version 1.20 | 6 | Copyright (c) 2004-2008 Lester "GaMerZ" Chan | 7 | | 8 | File Written By: | 9 | - Lester "GaMerZ" Chan | 10 | - http://lesterchan.net | 11 | | 12 | File Information: | 13 | - View/Download Files | 14 | - view.php | 15 | | 16 +----------------------------------------------------------------+ 17 */ 18 19 20 ### Require Config, Setting And Function Files 21 require('config.php'); 22 require('settings.php'); 23 require('functions.php'); 24 25 ### Start Timer 26 StartTimer(); 27 28 ### Get And Check File Path 29 $file = urldecode(stripslashes(trim($_GET['file']))); 30 if(strpos($file, '../') !== false || strpos($file, './') !== false || strpos($file, '//') !== false) { 31 display_error('Invalid Directory'); 32 } 33 $temp = explode('/', $file); 34 $file_name = $temp[(sizeof($temp)-1)]; 35 36 ### Get File Extension 37 $file_ext = explode('.', $file_name); 38 $file_ext = $file_ext[sizeof($file_ext)-1]; 39 $file_ext = strtolower($file_ext); 40 41 ### Check Whether File Is In The Ignore Files 42 if(in_array($file, $ignore_files)) { 43 display_error('Invalid Directory'); 44 } 45 46 ### Check Whether Extension Is In The Ignore Extensions 47 if(in_array($file_ext, $ignore_ext)) { 48 display_error('Invalid Extension'); 49 } 50 51 ### Check Whether File Exists 52 if(!is_file($root_directory.'/'.$file)) { 53 display_error('File Does Not Exist'); 54 } 55 56 ### If User Wants To Download Text Or Image 57 if(intval($_GET['dl']) == 1) { 58 $download_filename = $file_name; 59 $download_filename = preg_replace("/\s/e" , "_" , $download_filename); 60 header("Pragma: public"); 61 header("Expires: 0"); 62 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 63 header("Content-Type: application/force-download"); 64 header("Content-Type: application/octet-stream"); 65 header("Content-Type: application/download"); 66 header("Content-Disposition: attachment; filename=".basename($root_directory.'/'.$download_filename).";"); 67 header("Content-Transfer-Encoding: binary"); 68 header("Content-Length: ".filesize($root_directory.'/'.$file)); 69 @readfile($root_directory.'/'.$file); 70 exit(); 71 } 72 73 ### Display Text 74 if(in_array($file_ext, $text_ext)) { 75 // Get Number Of Lines In Text File 76 $lines = 0; 77 $lines_text = 'Lines'; 78 $text_size = format_size(filesize($root_directory.'/'.$file)); 79 ?> 80 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 81 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 82 <head> 83 <title><?php echo $site_name; ?> - Viewing Text File - <?php echo $file_name; ?></title> 84 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 85 <link rel="shortcut icon" href="<?php echo $gfe_url; ?>/resources/favicon.ico" type="image/ico" /> 86 <style type="text/css" media="screen, print"> 87 @import url( <?php echo $gfe_url; ?>/resources/style.css ); 88 </style> 89 <script src="<?php echo $gfe_url; ?>/resources/javascript.js" type="text/javascript"></script> 90 </head> 91 <body> 92 93 <!-- Breadcrumbs --> 94 <div id="Breadcrumbs"><?php echo breadcrumbs_view(); ?></div> 95 96 <!-- Text --> 97 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 98 <tr> 99 <td class="Header" style="text-align: center;" title="<?php echo $file_name; ?>"><?php echo $file_name; ?></td> 100 </tr> 101 <tr> 102 <td> 103 <?php if($file_ext == 'htm' || $file_ext == 'html'): ?> 104 <!-- Links To Toggle Between HTML Source/View --> 105 <div style="text-align: center;"><a href="#" onclick="show_htmlcode(); return false;" title="Show HTML Code">Show HTML Code</a> | <a href="#" onclick="show_htmlview(); return false;" title="Show HTML View">Show HTML View</a></div> 106 <?php endif; ?> 107 108 <!-- Display Source --> 109 <div id="DisplaySource"><?php echo display_text($root_directory.'/'.$file); ?></div> 110 111 <?php if($file_ext == 'htm' || $file_ext == 'html'): ?> 112 <!-- Display HTML View --> 113 <object id="DisplayHTML" data="<?php echo $root_url.'/'.$file; ?>" style="display: none; width: 100%; height: <?php echo ($lines*10); ?>px; border: 0px;" type="text/html"></object> 114 <?php endif; ?> 115 </td> 116 </tr> 117 </table> 118 119 <!-- Text Statistics --> 120 <?php if($lines <= 1) { $lines_text = 'Line'; } ?> 121 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 122 <tr> 123 <td class="Footer" style="width: 20%;" title="<?php echo $lines.' '.$lines_text; ?>"><?php echo $lines.' '.$lines_text; ?></td> 124 <td class="Footer" style="width: 60%; text-align: center;" title="Download '<?php echo $file_name; ?>'"><b><a href="<?php echo url($file,'download'); ?>">Download '<?php echo $file_name; ?>'</a></b></td> 125 <td class="Footer" style="width: 20%; text-align: center;" title="Size: <?php echo $text_size; ?>"><?php echo $text_size; ?></td> 126 </tr> 127 </table> 128 129 <!-- Current File Directory Path --> 130 <div id="BottomBreadcrumbs"><?php echo $root_url.'/'.$file; ?></div> 131 132 <?php 133 if($can_search) { 134 ?> 135 <!-- Search Engine --> 136 <form id="search" method="get" action="<?php echo $gfe_url; ?>/search.php"> 137 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 138 <tr> 139 <td title="Search For Files"> 140 <br />Search For Files: <input type="text" class="TextField" size="30" maxlength="30" name="search" /> 141 <input type="submit" value="Search" class="Button" /><br /> 142 <b>»</b> <a href="<?php echo $gfe_url; ?>/search.php">Advance Search</a> 143 </td> 144 </tr> 145 </table> 146 </form> 147 <?php 148 } 149 ?> 150 151 <!-- Copyright --> 152 <p style="text-align: center;"> 153 Powered By <a href="http://lesterchan.net/">GaMerZ File Explorer Version <?php echo $gfe_version; ?></a><br />Copyright © 2004-<?php echo date('Y'); ?> Lester "GaMerZ" Chan, All Rights Reserved.<br /><br />Page Generated In <?php echo StopTimer(); ?> Seconds 154 </p> 155 </body> 156 </html> 157 <?php 158 ### Dispay Image 159 } elseif(in_array($file_ext, $image_ext)) { 160 $temp_getimagesize = getimagesize($root_directory.'/'.$file); 161 if(!$temp_getimagesize) { 162 display_error('File Is Not A Valid Image'); 163 } 164 list($image_width, $image_height, $image_type, $image_attr) = $temp_getimagesize; 165 $image_size = format_size(filesize($root_directory.'/'.$file)); 166 ?> 167 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 168 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 169 <head> 170 <title><?php echo $site_name; ?> - Viewing Image - <?php echo $file_name; ?></title> 171 <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 172 <link rel="shortcut icon" href="<?php echo $gfe_url; ?>/resources/favicon.ico" type="image/ico" /> 173 <style type="text/css" media="screen, print"> 174 @import url( <?php echo $gfe_url; ?>/resources/style.css ); 175 </style> 176 <script src="<?php echo $gfe_url; ?>/resources/javascript.js" type="text/javascript"></script> 177 </head> 178 <body> 179 180 <!-- Breadcrumbs --> 181 <div id="Breadcrumbs"><?php echo breadcrumbs_view(); ?></div> 182 183 <!-- Image --> 184 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 185 <tr> 186 <td class="Header" style="text-align: center;" title="<?php echo $file_name; ?>"><?php echo $file_name; ?></td> 187 </tr> 188 <tr> 189 <td style="text-align: center;"><img src="<?php echo $root_url.'/'.$file; ?>" <?php echo $image_attr; ?> alt="GaMerZ.File.Viewer - Viewing Image - <?php echo $file_name; ?>" /></td> 190 </tr> 191 </table> 192 193 <!-- Image Statistics --> 194 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 195 <tr> 196 <td class="Footer" style="width: 20%; text-align: center;" title="Width: <?php echo $image_width; ?>px, Height:<?php echo $image_height; ?>px">Width: <?php echo $image_width; ?>px, Height:<?php echo $image_height; ?>px</td> 197 <td class="Footer" style="width: 60%; text-align: center;" title="Download '<?php echo $file_name; ?>'"><b><a href="<?php echo url($file,'download'); ?>">Download '<?php echo $file_name; ?>'</a></b></td> 198 <td class="Footer" style="width: 20%; text-align: center;" title="Size: <?php echo $image_size;?>"><?php echo $image_size;?></td> 199 </tr> 200 </table> 201 202 <!-- Current File Directory Path --> 203 <div id="BottomBreadcrumbs"><?php echo $root_url.'/'.$file; ?></div> 204 205 <?php 206 if($can_search) { 207 ?> 208 <!-- Search Engine --> 209 <form id="search" method="get" action="<?php echo $gfe_url; ?>/search.php"> 210 <table cellspacing="0" cellpadding="3" style="width: 100%; border: 0px;"> 211 <tr> 212 <td title="Search For Files"> 213 <br />Search For Files: <input type="text" class="TextField" size="30" maxlength="30" name="search" /> 214 <input type="submit" value="Search" class="Button" /><br /> 215 <b>»</b> <a href="<?php echo $gfe_url; ?>/search.php">Advanced Search</a> 216 </td> 217 </tr> 218 </table> 219 </form> 220 <?php 221 } 222 ?> 223 224 <!-- Copyright --> 225 <p style="text-align: center;"> 226 Powered By <a href="http://lesterchan.net/">GaMerZ File Explorer Version <?php echo $gfe_version; ?></a><br />Copyright © 2004-<?php echo date('Y'); ?> Lester "GaMerZ" Chan, All Rights Reserved.<br /><br />Page Generated In <?php echo StopTimer(); ?> Seconds 227 </p> 228 </body> 229 </html> 230 <?php 231 ### Display Download 232 } else { 233 $download_filename = $file_name; 234 $download_filename = preg_replace("/\s/e" , "_" , $download_filename); 235 header("Pragma: public"); 236 header("Expires: 0"); 237 header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 238 header("Content-Type: application/force-download"); 239 header("Content-Type: application/octet-stream"); 240 header("Content-Type: application/download"); 241 header("Content-Disposition: attachment; filename=".basename($root_directory.'/'.$download_filename).";"); 242 header("Content-Transfer-Encoding: binary"); 243 header("Content-Length: ".filesize($root_directory.'/'.$file)); 244 @readfile($root_directory.'/'.$file); 245 exit(); 246 } 247 ?> |
| 247 Lines | Download 'view.php' | 9.9KB |