Rev 15 | Rev 249 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php/*vim: set expandtab tabstop=4 shiftwidth=4: */// +------------------------------------------------------------------------------------------------------+// | PHP version 4.1 |// +------------------------------------------------------------------------------------------------------+// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |// +------------------------------------------------------------------------------------------------------+// | This library is free software; you can redistribute it and/or |// | modify it under the terms of the GNU General Public |// | License as published by the Free Software Foundation; either |// | version 2.1 of the License, or (at your option) any later version. |// | |// | This library is distributed in the hope that it will be useful, |// | but WITHOUT ANY WARRANTY; without even the implied warranty of |// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |// | General Public License for more details. |// | |// | You should have received a copy of the GNU General Public |// | License along with this library; if not, write to the Free Software |// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |// +------------------------------------------------------------------------------------------------------+// CVS : $Id: fichier.class.php,v 1.5 2005-10-04 10:13:33 alexandre_tb Exp $/*** Application projet** La classe fichier**@package projet//Auteur original :*@author Alexandre Granier <alexandre@tela-botanica.org>//Autres auteurs :*@author Aucun*@copyright Tela-Botanica 2000-2004*@version $Revision: 1.5 $// +------------------------------------------------------------------------------------------------------+*/// +------------------------------------------------------------------------------------------------------+// | ENTETE du PROGRAMME |// +------------------------------------------------------------------------------------------------------+include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;// +------------------------------------------------------------------------------------------------------+// | ENTETE du PROGRAMME |// +------------------------------------------------------------------------------------------------------+/*** class fichier* Cette classe représente un fichier au sens physique du terme. Elle fonctionne* pour les système UNIX. A faire : adaptation selon les système. L'objectif est de* gérer correctement l'upload de fichier.*/class fichier{/*** Attributes: ***//*** Le nom du fichier, avec son extension.* @access private*/var $_nom;/*** Le chemin UNIX ou Windows pour accéder au fichier sur le serveur (par ex;* /var/www/fichier.txt* @access private*/var $_chemin;/*** Cet attribut contient une valeur du type 755, indiquant les droits afférent à un* fichier selon le système UNIX (propriétaire, groupe, autres)* @access private*/var $_droits_unix;/*** Le type indique si le fichier est un répertoire, un lien ou un fichier.* @access private*/var $_type = 'fichier';/*** l'identifiant du type mime.* @access private*/var $_type_mime;/*** Le chemin vers le fichier, en partant du répertoire de travail.* @access private*/var $_prefixe_chemin;/***** @return void* @access public*/function fichier( $chemin, &$objetDB){$this->_chemin = $chemin ;// On analyse l'extension pour découvrir le type mime$partie_chemin = pathinfo ($this->_chemin) ;if (is_object($objetDB) && isset($partie_chemin['extension'])) {$this->_type_mime = type_fichier_mime::factory ($partie_chemin['extension'], $objetDB) ;}// calcul du typeif (is_dir ($this->_chemin)) $this->_type = 'repertoire' ;} // end of member function fichier/*** Le constructeur de la classe.** @param string chemin Le chemin du fichier sur le serveur.* @return fichier* @access public*/function __construct( $chemin, &$objetDB){$this->fichier($chemin, $objetDB);} // end of member function __construct/***** @return void* @access public*/function suppression(){if ($this->_type == 'repertoire') rmdir ($this->_chemin) ;if ($this->_type == 'fichier') unlink ($this->_chemin) ;} // end of member function suppression/*** Réalise l'upload d'un fichier vers chemin_destination.** @param string chemin_destination Il s'agit du chemin UNIX de destination du fichier. Le script doit avoir les* droits en écriture sur le répertoire.* @global mixed une référence vers un objet HTML_QuickForm_File* @return void* @access public*/function upload( $chemin_destination ){if (move_uploaded_file($_FILES['fichier']['tmp_name'], $chemin_destination)) {return true ;} else {return false ;}} // end of member function upload/*** Déplace un fichier, renvoie vrai en cas de succès.** @param string origine L'emplacement de départ du fichier.* @param string destination Le répertoire d'arrivé.* @return bool* @access public*/function deplace( $origine, $destination ){if (copy ($origine, $destination )) {if (unlink($origine)) return true ;}return false ;} // end of member function deplace/***** @param int id_type_mime L'identifiant du type mime du document.* @return type_fichier_mime* @access public*/function getTypeMime( ){return $this->_type_mime;} // end of member function getTypeMime/*** Renvoie vrai si le document est un répertoire.** @return bool* @access public*/function isRepertoire( ){return is_dir ($this->_chemin) ;} // end of member function isRepertoire/***** @param int id_type_mime L'identifiant du type mime.* @return void* @access public*/function setTypeMime( $id_type_mime ){$this->_type_mime = $id_type_mime ;} // end of member function set TypeMime/*** Renvoie la taille du fichier en octet. Nécessite un accès au disque.** @return int* @access public*/function getTaille( ){if ($this->isRepertoire()) {return $this->_tailleRepertoire($this->_chemin) ;}return filesize ($this->_chemin) ;} // end of member function getTaille/*** Renovie le nom du fichier, sur le disque.** @return string* @access public*/function getNom( ){} // end of member function getNom/*** Renvoie le chemin du fichier.** @return string* @access public*/function getChemin( ){return $this->_chemin ;} // end of member function getChemin/*** Permet de calculer la taille en octet du repertoire courrant** @return int* @access protected*/function _tailleRepertoire($rep){$taille = 0 ;$liste_fichier = scandir ($rep) ;foreach ($liste_fichier as $key => $value) {if (is_dir ($rep."/".$value) && $value != ".." && $value != ".") {$taille += $this->_tailleRepertoire ($rep.$value."/") ;} else {if ($value != '..' && $value != '.') $taille += filesize ($rep.$value) ;}}return $taille ;} // end of member function _tailleRepertoire/*** initAttributes sets all fichier attributes to its default value make* sure to call this method within your class constructor*/function initAttributes( ){$this->_type = 'fichier';}} // end of fichierif(!function_exists("scandir")){function scandir($dirstr){// php.net/scandir (PHP5)$files = array();$fh = opendir($dirstr);while (false !== ($filename = readdir($fh))){array_push($files, $filename);}closedir($fh);return $files;}}?>