download.html.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php include '../../common/view/header.lite.html.php';?>
  2. <?php js::set('fileID', $file->id);?>
  3. <style>
  4. #imageFile {text-align: center; padding: 0; margin: 0 -10px;}
  5. #imageFile img {max-width: 100%;}
  6. #txtFile {padding: 5px 0; margin: 0 -10px;}
  7. #txtFile pre {margin: 0;}
  8. #txtFile div {overflow-x: auto;}
  9. #titlebar span {float: right; padding-right: 25px;}
  10. .main-header .btn-toolbar {margin-left: 8px;}
  11. </style>
  12. <main id="main">
  13. <div class="container">
  14. <div id='mainContent' class='main-content'>
  15. <div class='main-header clearfix'>
  16. <h2 class='pull-left'><?php echo $lang->file->preview;?></h2>
  17. <?php if($fileType == 'txt'):?>
  18. <div class='btn-toolbar pull-left w-120px'><?php echo html::select('charset', $config->file->charset, $charset, "onchange='setCharset(this.value)' class='form-control'");?></div>
  19. <?php endif;?>
  20. </div>
  21. <?php if($fileType == 'image'):?>
  22. <div id='imageFile'><?php echo html::image($this->createLink('file', 'read', "fileID=$file->id"));?></div>
  23. <?php else:?>
  24. <div id='txtFile'>
  25. <?php
  26. $fileContent = file_get_contents($file->realPath);
  27. if($charset != $config->charset)
  28. {
  29. $fileContent = helper::convertEncoding($fileContent, $charset . "//IGNORE", $config->charset);
  30. }
  31. else
  32. {
  33. if(extension_loaded('mbstring'))
  34. {
  35. $encoding = mb_detect_encoding($fileContent, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
  36. if($encoding != 'UTF-8') $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset);
  37. }
  38. else
  39. {
  40. $encoding = 'UTF-8';
  41. if($config->default->lang == 'zh-cn') $encoding = 'GBK';
  42. if($config->default->lang == 'zh-tw') $encoding = 'BIG5';
  43. $fileContent = helper::convertEncoding($fileContent, $encoding, $config->charset);
  44. }
  45. }
  46. echo "<pre>" . htmlSpecialString($fileContent) . "</pre>";
  47. ?>
  48. </div>
  49. <?php endif;?>
  50. </div>
  51. </div>
  52. </main>
  53. <script>
  54. function setCharset(charset)
  55. {
  56. var link = createLink('file', 'download', 'fileID=' + fileID + '&mouse=left');
  57. link += link.indexOf('?') >= 0 ? '&' : '?';
  58. link += 'charset=' + charset;
  59. location.href = link;
  60. }
  61. </script>
  62. <?php include '../../common/view/footer.lite.html.php';?>