<?php
//#################################################################################################
// Class File
//#################################################################################################
// chillyCMS - Content Management System
// Copyright (C) 2008
// Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//
// This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
defined('DOIT') or die('Restricted access');
class File {
//Class variables//////////////////////////////////////////////////////////////////////////
private $file; //original filedata
private $ext; //e.g. zip
private $name; //the name without extension
private $mime; //php mimetype
private $size; //filesize
private $type; //type for thumbnail preview image
private $path; //path of the file inside /media
//Functions////////////////////////////////////////////////////////////////////////////////
//Constructor, creates a new User
public function __construct($file) {
include(PATH."/core/mime.include.php");
$file=realpath($file);
$this->file=$file;
if (is_file($file)) {
$found=false;
foreach ($mime_types as $type=>$array) {
foreach ($array as $key=>$value) {
if (strtolower(substr($file,-strlen($key)))==strtolower($key)) {
$this->ext=substr($file,-strlen($key));
$this->mime=$value;
$this->size=filesize($file);
$this->type=$type;
$myfile=explode(DIRECTORY_SEPARATOR,substr($file,0,(strlen($file)-(strlen($key)+1))));
$this->name=array_pop($myfile);
$this->path=implode("/",$myfile);
if ($this->path!="") { $this->path.="/"; }
//check "real" mimetype
$mime = $this->get_mimetype();
//workaround for tar.gz: TODO
if ($mime=="application/x-gzip") {
if ($this->ext=="tar.gz") {
$mime="application/x-compressed-tar";
}
}
if ($mime==$value) {
$found=true;
break;
}
}
}
if ($found) { break; }
}
} else {
$this->ext = $this->name = $this->mime = $this->size = $this->image = $this->path = false;
}
}
//Getter
public function __get($name) {
if (isset($name, $this->$name)) { return $this->$name; }
else { return false; }
}
//Get mimetype
public function get_mimetype() {
$myfile = substr(cut_doubledots($this->file),strlen(PATH));
$url=URL."/".$myfile;
if ($meta = @get_headers($url)) {
return @substr($meta[8],14);
} else {
return $this->mime;
}
}
}
?>