file.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 if (!class_exists('Object')) {
00032 uses ('object');
00033 }
00034
00035 if (!class_exists('Folder')) {
00036 uses ('folder');
00037 }
00038
00039
00040
00041
00042
00043
00044 class File extends Object{
00045
00046
00047
00048
00049
00050 var $folder = null;
00051
00052
00053
00054
00055
00056 var $name = null;
00057
00058
00059
00060
00061
00062
00063
00064 function __construct($path, $create = false) {
00065 parent::__construct();
00066 $this->folder = new Folder(dirname($path), $create);
00067 $this->name = basename($path);
00068 if (!$this->exists()) {
00069 if ($create === true) {
00070 if (!$this->create()) {
00071 return false;
00072 }
00073 } else {
00074 return false;
00075 }
00076 }
00077 }
00078
00079
00080
00081
00082
00083 function read() {
00084 $contents = file_get_contents($this->getFullPath());
00085 return $contents;
00086 }
00087
00088
00089
00090
00091
00092
00093 function append($data) {
00094 return $this->write($data, 'a');
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 function write($data, $mode = 'w') {
00104 $file = $this->getFullPath();
00105 if (!($handle = fopen($file, $mode))) {
00106 print ("[File] Could not open $file with mode $mode!");
00107 return false;
00108 }
00109
00110 if (!fwrite($handle, $data)) {
00111 return false;
00112 }
00113
00114 if (!fclose($handle)) {
00115 return false;
00116 }
00117 return true;
00118 }
00119
00120
00121
00122
00123
00124
00125 function getMd5($force = false) {
00126 $md5 = '';
00127 if ($force == true || $this->getSize(false) < MAX_MD5SIZE) {
00128 $md5 = md5_file($this->getFullPath());
00129 }
00130 return $md5;
00131 }
00132
00133
00134
00135
00136
00137
00138 function getSize() {
00139 $size = filesize($this->getFullPath());
00140 return $size;
00141 }
00142
00143
00144
00145
00146
00147 function getExt() {
00148 $ext = '';
00149 $parts = explode('.', $this->getName());
00150
00151 if (count($parts) > 1) {
00152 $ext = array_pop($parts);
00153 } else {
00154 $ext = '';
00155 }
00156 return $ext;
00157 }
00158
00159
00160
00161
00162
00163 function getName() {
00164 return $this->name;
00165 }
00166
00167
00168
00169
00170
00171 function getOwner() {
00172 $fileowner = fileowner($this->getFullPath());
00173 return $fileowner;
00174 }
00175
00176
00177
00178
00179
00180 function getGroup() {
00181 $filegroup = filegroup($this->getFullPath());
00182 return $filegroup;
00183 }
00184
00185
00186
00187
00188
00189 function create() {
00190 $dir = $this->folder->pwd();
00191
00192 if (file_exists($dir) && is_dir($dir) && is_writable($dir) && !$this->exists()) {
00193 if (!touch($this->getFullPath())) {
00194 print ('[File] Could not create '.$this->getName().'!');
00195 return false;
00196 } else {
00197 return true;
00198 }
00199 } else {
00200 print ('[File] Could not create '.$this->getName().'!');
00201 return false;
00202 }
00203 }
00204
00205
00206
00207
00208
00209 function exists() {
00210 $exists = file_exists($this->getFullPath());
00211 return $exists;
00212 }
00213
00214
00215
00216
00217
00218 function delete() {
00219 $unlink = unlink($this->getFullPath());
00220 return $unlink;
00221 }
00222
00223
00224
00225
00226
00227 function writable() {
00228 $writable = is_writable($this->getFullPath());
00229 return $writable;
00230 }
00231
00232
00233
00234
00235
00236 function executable() {
00237 $executable = is_executable($this->getFullPath());
00238 return $executable;
00239 }
00240
00241
00242
00243
00244
00245 function readable() {
00246 $readable = is_readable($this->getFullPath());
00247 return $readable;
00248 }
00249
00250
00251
00252
00253
00254 function lastAccess() {
00255 $fileatime = fileatime($this->getFullPath());
00256 return $fileatime;
00257 }
00258
00259
00260
00261
00262
00263 function lastChange() {
00264 $filemtime = filemtime($this->getFullPath());
00265 return $filemtime;
00266 }
00267
00268
00269
00270
00271
00272 function getFolder() {
00273 return $this->folder;
00274 }
00275
00276
00277
00278
00279
00280 function getChmod() {
00281 $substr = substr(sprintf('%o', fileperms($this->getFullPath())), -4);
00282 return $substr;
00283 }
00284
00285
00286
00287
00288
00289 function getFullPath() {
00290 return $this->folder->slashTerm($this->folder->pwd()) . $this->getName();
00291 }
00292 }
00293 ?>