PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/ php-ppcms/includes/classes/core.file.class.php

http://php-ppcms.googlecode.com/
PHP | 170 lines | 123 code | 34 blank | 13 comment | 22 complexity | 7d8398c618eaf99738f34255fd59621a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. * (c) 2009, jianyuzhu@gmail.com
  5. * All rights reserved
  6. * This script is part of the PPEMI project.
  7. ***************************************************************/
  8. class CoreFile {
  9. var $file;
  10. var $is_parsed;
  11. var $is_file;
  12. var $filepath;
  13. var $filename;
  14. var $filesize;
  15. //var $filetype;
  16. var $extension;
  17. var $permission;
  18. var $is_image;
  19. var $image_width;
  20. var $image_height;
  21. var $image_type;
  22. var $image_attribute;
  23. var $is_flash = false;
  24. //constructor
  25. function CoreFile($file) {
  26. $this->file = $file;
  27. $this->is_parsed = false;
  28. $this->is_file = false;
  29. $this->is_image = false;
  30. $this->is_flash = false;
  31. }
  32. function setFile($file) {
  33. $this->file = $file;
  34. }
  35. function getFile() {
  36. return $this->file;
  37. }
  38. function setFilename($filename) {
  39. $this->filename = $filename;
  40. }
  41. function getFilename() {
  42. return $this->filename;
  43. }
  44. //methods
  45. function parse() {
  46. if( !$this->_not_null($this->file) ) {
  47. return false;
  48. }
  49. if( is_file($this->file) ) {
  50. $this->is_file = true;
  51. } else {
  52. $this->is_file = false;
  53. return false;
  54. }
  55. $this->filepath = dirname($this->file);
  56. $this->filename = basename($this->file);
  57. $this->extension = substr($this->file, strrpos($this->file, '.'));
  58. $this->filesize = filesize($this->file);
  59. $this->permission = substr(sprintf('%o', fileperms($this->file)), -4);
  60. $image_size = @getimagesize($this->file);
  61. if( $image_size ) {
  62. $this->is_image = true;
  63. $this->image_width = $image_size['0'];
  64. $this->image_height = $image_size['1'];
  65. $this->image_type = $image_size['2'];
  66. $this->image_attribute = $image_size['3'];
  67. if( $this->image_type == 4 || strtolower(substr($this->file, -4)) == '.swf' ) {
  68. $this->is_flash = true;
  69. }
  70. }
  71. $this->is_parsed = true;
  72. }
  73. function delete() {
  74. if( file_exists($this->file) ) {
  75. @unlink($this->file);
  76. }
  77. }
  78. function copyfile($newfile, $override = false) {
  79. if( !$this->_not_null($newfile) ) {
  80. return false;
  81. }
  82. if( file_exists($newfile) ) {
  83. if( $override == false ) {
  84. return true;
  85. } else {
  86. copy($this->file, $newfile);
  87. return true;
  88. }
  89. } else {
  90. copy($this->file, $newfile);
  91. return true;
  92. }
  93. }
  94. function checkFile() {
  95. }
  96. function getImageWidth() {
  97. if( $this->is_parsed == false ) {
  98. $this->parse();
  99. }
  100. return $this->image_width;
  101. }
  102. function getImageHeight() {
  103. if( $this->is_parsed == false ) {
  104. $this->parse();
  105. }
  106. return $this->image_height;
  107. }
  108. function getFileAttribute() {
  109. if( $this->is_parsed == false ) {
  110. $this->parse();
  111. }
  112. $attribute = 'filesize=' . $this->filesize . "\n"
  113. . 'permission=' . $this->permission . "\n"
  114. . 'is_image=' . (($this->is_image == true) ? '1' : '0') . "\n"
  115. . 'image_width=' . $this->image_width . "\n"
  116. . 'image_height=' . $this->image_height . "\n"
  117. . 'image_type=' . $this->image_type . "\n"
  118. . 'image_attribute=' . $this->image_attribute . "\n";
  119. return $attribute;
  120. }
  121. //private
  122. function _not_null($value) {
  123. return util_not_null($value);
  124. }
  125. }
  126. class MultiFileBase {
  127. var $xxx;
  128. //constructor
  129. function MultiFileBase() {
  130. }
  131. //methods
  132. function parse() {
  133. }
  134. }
  135. //
  136. ?>