/ php-ppcms/includes/classes/core.file.class.php
PHP | 170 lines | 123 code | 34 blank | 13 comment | 22 complexity | 7d8398c618eaf99738f34255fd59621a MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
- <?php
- /***************************************************************
- * Copyright notice
- * (c) 2009, jianyuzhu@gmail.com
- * All rights reserved
- * This script is part of the PPEMI project.
- ***************************************************************/
-
- class CoreFile {
- var $file;
-
- var $is_parsed;
- var $is_file;
-
- var $filepath;
- var $filename;
- var $filesize;
- //var $filetype;
- var $extension;
- var $permission;
-
- var $is_image;
- var $image_width;
- var $image_height;
- var $image_type;
- var $image_attribute;
-
- var $is_flash = false;
-
- //constructor
- function CoreFile($file) {
- $this->file = $file;
-
- $this->is_parsed = false;
- $this->is_file = false;
- $this->is_image = false;
- $this->is_flash = false;
- }
-
- function setFile($file) {
- $this->file = $file;
- }
-
- function getFile() {
- return $this->file;
- }
-
- function setFilename($filename) {
- $this->filename = $filename;
- }
-
- function getFilename() {
- return $this->filename;
- }
-
- //methods
- function parse() {
- if( !$this->_not_null($this->file) ) {
- return false;
- }
- if( is_file($this->file) ) {
- $this->is_file = true;
- } else {
- $this->is_file = false;
- return false;
- }
-
- $this->filepath = dirname($this->file);
- $this->filename = basename($this->file);
- $this->extension = substr($this->file, strrpos($this->file, '.'));
-
- $this->filesize = filesize($this->file);
- $this->permission = substr(sprintf('%o', fileperms($this->file)), -4);
-
- $image_size = @getimagesize($this->file);
- if( $image_size ) {
- $this->is_image = true;
- $this->image_width = $image_size['0'];
- $this->image_height = $image_size['1'];
- $this->image_type = $image_size['2'];
- $this->image_attribute = $image_size['3'];
-
- if( $this->image_type == 4 || strtolower(substr($this->file, -4)) == '.swf' ) {
- $this->is_flash = true;
- }
- }
-
- $this->is_parsed = true;
- }
-
- function delete() {
- if( file_exists($this->file) ) {
- @unlink($this->file);
- }
- }
-
- function copyfile($newfile, $override = false) {
- if( !$this->_not_null($newfile) ) {
- return false;
- }
- if( file_exists($newfile) ) {
- if( $override == false ) {
- return true;
- } else {
- copy($this->file, $newfile);
- return true;
- }
- } else {
- copy($this->file, $newfile);
- return true;
- }
- }
-
- function checkFile() {
-
- }
-
- function getImageWidth() {
- if( $this->is_parsed == false ) {
- $this->parse();
- }
-
- return $this->image_width;
- }
-
- function getImageHeight() {
- if( $this->is_parsed == false ) {
- $this->parse();
- }
-
- return $this->image_height;
- }
-
- function getFileAttribute() {
- if( $this->is_parsed == false ) {
- $this->parse();
- }
-
- $attribute = 'filesize=' . $this->filesize . "\n"
- . 'permission=' . $this->permission . "\n"
- . 'is_image=' . (($this->is_image == true) ? '1' : '0') . "\n"
- . 'image_width=' . $this->image_width . "\n"
- . 'image_height=' . $this->image_height . "\n"
- . 'image_type=' . $this->image_type . "\n"
- . 'image_attribute=' . $this->image_attribute . "\n";
-
- return $attribute;
- }
-
- //private
- function _not_null($value) {
- return util_not_null($value);
- }
- }
-
- class MultiFileBase {
- var $xxx;
-
- //constructor
- function MultiFileBase() {
-
- }
-
- //methods
- function parse() {
-
- }
- }
- //
- ?>