Subversion Repositories Applications.projet

Rev

Rev 305 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 305 Rev 431
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU General Public                                                  |
9
// | modify it under the terms of the GNU General Public                                                  |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | General Public License for more details.                                                             |
16
// | General Public License for more details.                                                             |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU General Public                                            |
18
// | You should have received a copy of the GNU General Public                                            |
19
// | License along with this library; if not, write to the Free Software                                  |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: fichier.class.php,v 1.8 2008-08-25 15:16:25 alexandre_tb Exp $
22
// CVS : $Id: fichier.class.php,v 1.7 2007-06-25 12:15:06 alexandre_tb Exp $
23
/**
23
/**
24
* Application projet
24
* Application projet
25
*
25
*
26
* La classe fichier
26
* La classe fichier
27
*
27
*
28
*@package projet
28
*@package projet
29
//Auteur original :
29
//Auteur original :
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
31
//Autres auteurs :
31
//Autres auteurs :
32
*@author        Aucun
32
*@author        Aucun
33
*@copyright     Tela-Botanica 2000-2004
33
*@copyright     Tela-Botanica 2000-2004
34
*@version       $Revision: 1.8 $
34
*@version       $Revision: 1.7 $
35
// +------------------------------------------------------------------------------------------------------+
35
// +------------------------------------------------------------------------------------------------------+
36
*/
36
*/
37
 
37
 
38
 
38
 
39
// +------------------------------------------------------------------------------------------------------+
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                            ENTETE du PROGRAMME                                       |
40
// |                                            ENTETE du PROGRAMME                                       |
41
// +------------------------------------------------------------------------------------------------------+
41
// +------------------------------------------------------------------------------------------------------+
42
 
42
 
43
include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
43
include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
44
 
44
 
45
// +------------------------------------------------------------------------------------------------------+
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                            ENTETE du PROGRAMME                                       |
46
// |                                            ENTETE du PROGRAMME                                       |
47
// +------------------------------------------------------------------------------------------------------+
47
// +------------------------------------------------------------------------------------------------------+
48
 
48
 
49
 
49
 
50
/**
50
/**
51
 * class fichier
51
 * class fichier
52
 * Cette classe représente un fichier au sens physique du terme. Elle fonctionne
52
 * Cette classe représente un fichier au sens physique du terme. Elle fonctionne
53
 * pour les système UNIX.  A faire : adaptation selon les système. L'objectif est de
53
 * pour les système UNIX.  A faire : adaptation selon les système. L'objectif est de
54
 * gérer correctement l'upload de fichier.
54
 * gérer correctement l'upload de fichier.
55
 */
55
 */
56
class fichier
56
class fichier
57
{
57
{
58
    /*** Attributes: ***/
58
    /*** Attributes: ***/
59
    /**
59
    /**
60
     * Le nom du fichier, avec son extension.
60
     * Le nom du fichier, avec son extension.
61
     * @access private
61
     * @access private
62
     */
62
     */
63
    var $_nom;
63
    var $_nom;
64
    /**
64
    /**
65
     * Le chemin UNIX ou Windows pour accéder au fichier sur le serveur (par ex;
65
     * Le chemin UNIX ou Windows pour accéder au fichier sur le serveur (par ex;
66
     * /var/www/fichier.txt
66
     * /var/www/fichier.txt
67
     * @access private
67
     * @access private
68
     */
68
     */
69
    var $_chemin;
69
    var $_chemin;
70
    /**
70
    /**
71
     * Cet attribut contient une valeur du type 755, indiquant les droits afférent à un
71
     * Cet attribut contient une valeur du type 755, indiquant les droits afférent à un
72
     * fichier selon le système UNIX (propriétaire, groupe, autres)
72
     * fichier selon le système UNIX (propriétaire, groupe, autres)
73
     * @access private
73
     * @access private
74
     */
74
     */
75
    var $_droits_unix;
75
    var $_droits_unix;
76
    /**
76
    /**
77
     * Le type indique si le fichier est un répertoire, un lien ou un fichier.
77
     * Le type indique si le fichier est un répertoire, un lien ou un fichier.
78
     * @access private
78
     * @access private
79
     */
79
     */
80
    var $_type = 'fichier';
80
    var $_type = 'fichier';
81
    
81
    
82
    /**
82
    /**
83
     * l'identifiant du type mime.
83
     * l'identifiant du type mime.
84
     * @access private
84
     * @access private
85
     */
85
     */
86
    var $_type_mime;
86
    var $_type_mime;
87
    
87
    
88
    /**
88
    /**
89
     * Le chemin vers le fichier, en partant du répertoire de travail.
89
     * Le chemin vers le fichier, en partant du répertoire de travail.
90
     * @access private
90
     * @access private
91
     */
91
     */
92
    var $_prefixe_chemin;
92
    var $_prefixe_chemin;
93
 
93
 
94
    /**
94
    /**
95
     * 
95
     * 
96
     *
96
     *
97
     * @return void
97
     * @return void
98
     * @access public
98
     * @access public
99
     */
99
     */
100
    function fichier( $chemin, &$objetDB)
100
    function fichier( $chemin, &$objetDB)
101
    {
101
    {
102
        $this->_chemin = $chemin ;
102
        $this->_chemin = $chemin ;
103
        // On analyse l'extension pour découvrir le type mime
103
        // On analyse l'extension pour découvrir le type mime
104
        $partie_chemin = pathinfo ($this->_chemin) ;
104
        $partie_chemin = pathinfo ($this->_chemin) ;
105
        
105
        
106
        if (is_object($objetDB) && isset($partie_chemin['extension'])) {
106
        if (is_object($objetDB) && isset($partie_chemin['extension'])) {
107
            $this->_type_mime = type_fichier_mime::factory ($partie_chemin['extension']) ;
107
            $this->_type_mime = type_fichier_mime::factory ($partie_chemin['extension']) ;
108
        }
108
        }
109
        // calcul du type
109
        // calcul du type
110
        if (is_dir ($this->_chemin)) $this->_type = 'repertoire' ;
110
        if (is_dir ($this->_chemin)) $this->_type = 'repertoire' ;
111
    } // end of member function fichier
111
    } // end of member function fichier
112
 
112
 
113
    /**
113
    /**
114
     * Le constructeur de la classe.
114
     * Le constructeur de la classe.
115
     *
115
     *
116
     * @param string chemin Le chemin du fichier sur le serveur.
116
     * @param string chemin Le chemin du fichier sur le serveur.
117
     * @return fichier
117
     * @return fichier
118
     * @access public
118
     * @access public
119
     */
119
     */
120
    function __construct( $chemin, &$objetDB)
120
    function __construct( $chemin, &$objetDB)
121
    {
121
    {
122
        $this->fichier($chemin, $objetDB);
122
        $this->fichier($chemin, $objetDB);
123
        
123
        
124
    } // end of member function __construct
124
    } // end of member function __construct
125
 
125
 
126
    /**
126
    /**
127
     * 
127
     * 
128
     *
128
     *
129
     * @return void
129
     * @return void
130
     * @access public
130
     * @access public
131
     */
131
     */
132
    function suppression()
132
    function suppression()
133
    {
133
    {
134
        if ($this->_type == 'repertoire') rmdir ($this->_chemin) ;
134
        if ($this->_type == 'repertoire') rmdir ($this->_chemin) ;
135
        if ($this->_type == 'fichier') unlink ($this->_chemin) ;
135
        if ($this->_type == 'fichier') unlink ($this->_chemin) ;
136
    } // end of member function suppression
136
    } // end of member function suppression
137
 
137
 
138
    /**
138
    /**
139
     * Réalise l'upload d'un fichier vers chemin_destination.
139
     * Réalise l'upload d'un fichier vers chemin_destination.
140
     *
140
     *
141
     * @param string chemin_destination Il s'agit du chemin UNIX de destination du fichier. Le script doit avoir les
141
     * @param string chemin_destination Il s'agit du chemin UNIX de destination du fichier. Le script doit avoir les
142
     * droits en écriture sur le répertoire.
142
     * droits en écriture sur le répertoire.
143
     * @global    mixed une référence vers un objet HTML_QuickForm_File
143
     * @global    mixed une référence vers un objet HTML_QuickForm_File
144
     * @return void
144
     * @return void
145
     * @access public
145
     * @access public
146
     */
146
     */
147
    function upload( $chemin_destination )
147
    function upload( $chemin_destination )
148
    {
148
    {
149
        if (move_uploaded_file($_FILES['fichier']['tmp_name'], $chemin_destination)) {
149
        if (move_uploaded_file($_FILES['fichier']['tmp_name'], $chemin_destination)) {
150
            return true ;
150
            return true ;
151
        } else {
151
        } else {
152
            return false ;
152
            return false ;
153
        }
153
        }
154
    } // end of member function upload
154
    } // end of member function upload
155
 
155
 
156
    /**
156
    /**
157
     * Déplace un fichier, renvoie vrai en cas de succès.
157
     * Déplace un fichier, renvoie vrai en cas de succès.
158
     *
158
     *
159
     * @param string origine L'emplacement de départ du fichier.
159
     * @param string origine L'emplacement de départ du fichier.
160
     * @param string destination Le répertoire d'arrivé.
160
     * @param string destination Le répertoire d'arrivé.
161
     * @return bool
161
     * @return bool
162
     * @access public
162
     * @access public
163
     */
163
     */
164
    function deplace( $origine,  $destination )
164
    function deplace( $origine,  $destination )
165
    {
165
    {
166
        if (rename ($origine, $destination )) return true ;
166
        if (rename ($origine, $destination )) return true ;
167
        return false ;
167
        return false ;
168
    } // end of member function deplace
168
    } // end of member function deplace
169
 
169
 
170
    /**
170
    /**
171
     * 
171
     * 
172
     *
172
     *
173
     * @param int id_type_mime L'identifiant du type mime du document.
173
     * @param int id_type_mime L'identifiant du type mime du document.
174
     * @return type_fichier_mime
174
     * @return type_fichier_mime
175
     * @access public
175
     * @access public
176
     */
176
     */
177
    function getTypeMime(  )
177
    function getTypeMime(  )
178
    {
178
    {
179
        return $this->_type_mime;
179
        return $this->_type_mime;
180
        
180
        
181
    } // end of member function getTypeMime
181
    } // end of member function getTypeMime
182
 
182
 
183
    /**
183
    /**
184
     * Renvoie vrai si le document est un répertoire.
184
     * Renvoie vrai si le document est un répertoire.
185
     *
185
     *
186
     * @return bool
186
     * @return bool
187
     * @access public
187
     * @access public
188
     */
188
     */
189
    function isRepertoire( )
189
    function isRepertoire( )
190
    {	$isRep = is_dir ($this->_chemin) ;
190
    {	$isRep = is_dir ($this->_chemin) ;
191
        return $isRep ;
191
        return $isRep ;
192
    } // end of member function isRepertoire
192
    } // end of member function isRepertoire
193
 
193
 
194
 
194
 
195
    /**
195
    /**
196
     * 
196
     * 
197
     *
197
     *
198
     * @param int id_type_mime L'identifiant du type mime.
198
     * @param int id_type_mime L'identifiant du type mime.
199
     * @return void
199
     * @return void
200
     * @access public
200
     * @access public
201
     */
201
     */
202
    function setTypeMime( $id_type_mime )
202
    function setTypeMime( $id_type_mime )
203
    {
203
    {
204
        $this->_type_mime = $id_type_mime ;
204
        $this->_type_mime = $id_type_mime ;
205
    } // end of member function set TypeMime
205
    } // end of member function set TypeMime
206
 
206
 
207
 
207
 
208
    /**
208
    /**
209
     * Renvoie la taille du fichier en octet. Nécessite un accès au disque.
209
     * Renvoie la taille du fichier en octet. Nécessite un accès au disque.
210
     *
210
     *
211
     * @return int
211
     * @return int
212
     * @access public
212
     * @access public
213
     */
213
     */
214
    function getTaille( )
214
    function getTaille( )
215
    {
215
    {
216
        if ($this->isRepertoire()) {
216
        if ($this->isRepertoire()) {
217
            return $this->_tailleRepertoire($this->_chemin) ;
217
            return $this->_tailleRepertoire($this->_chemin) ;
218
        }
218
        }
219
        return @filesize ($this->_chemin) ;
219
        return @filesize ($this->_chemin) ;
220
    } // end of member function getTaille
220
    } // end of member function getTaille
221
 
221
 
222
    /**
222
    /**
223
     * Renovie le nom du fichier, sur le disque.
223
     * Renovie le nom du fichier, sur le disque.
224
     *
224
     *
225
     * @return string
225
     * @return string
226
     * @access public
226
     * @access public
227
     */
227
     */
228
    function getNom( )
228
    function getNom( )
229
    {
229
    {
230
        
230
        
231
    } // end of member function getNom
231
    } // end of member function getNom
232
 
232
 
233
    /**
233
    /**
234
     * Renvoie le chemin du fichier.
234
     * Renvoie le chemin du fichier.
235
     *
235
     *
236
     * @return string
236
     * @return string
237
     * @access public
237
     * @access public
238
     */
238
     */
239
    function getChemin( )
239
    function getChemin( )
240
    {
240
    {
241
        return $this->_chemin ;
241
        return $this->_chemin ;
242
    } // end of member function getChemin
242
    } // end of member function getChemin
243
 
243
 
244
    /**
244
    /**
245
     * Permet de calculer la taille en octet du repertoire courrant
245
     * Permet de calculer la taille en octet du repertoire courrant
246
     *
246
     *
247
     * @return int
247
     * @return int
248
     * @access protected
248
     * @access protected
249
     */
249
     */
250
    function _tailleRepertoire($rep)
250
    function _tailleRepertoire($rep)
251
    {
251
    {
252
        $taille = 0 ;
252
        $taille = 0 ;
253
        $liste_fichier = scandir ($rep) ;
253
        $liste_fichier = scandir ($rep) ;
254
        foreach ($liste_fichier as $key => $value) {
254
        foreach ($liste_fichier as $key => $value) {
255
            if (is_dir ($rep."/".$value) && $value != ".." && $value != ".") {
255
            if (is_dir ($rep."/".$value) && $value != ".." && $value != ".") {
256
            
256
            
257
                $taille += $this->_tailleRepertoire ($rep.$value."/") ;
257
                $taille += $this->_tailleRepertoire ($rep.$value."/") ;
258
            } else {
258
            } else {
259
                if ($value != '..' && $value != '.') $taille += @filesize ($rep.$value) ;
259
                if ($value != '..' && $value != '.') $taille += @filesize ($rep.$value) ;
260
            }
260
            }
261
        }
261
        }
262
        return $taille ;
262
        return $taille ;
263
    } // end of member function _tailleRepertoire
263
    } // end of member function _tailleRepertoire
264
 
264
 
265
 
265
 
266
    /**
266
    /**
267
     * initAttributes sets all fichier attributes to its default                    value make
267
     * initAttributes sets all fichier attributes to its default                    value make
268
     * sure to call this method within your class constructor
268
     * sure to call this method within your class constructor
269
     */
269
     */
270
    function initAttributes( )
270
    function initAttributes( )
271
    {
271
    {
272
        $this->_type = 'fichier';
272
        $this->_type = 'fichier';
273
    }
273
    }
274
 
274
 
275
 
275
 
276
} // end of fichier
276
} // end of fichier
277
 
277
 
278
if(!function_exists("scandir"))
278
if(!function_exists("scandir"))
279
{
279
{
280
  function scandir($dirstr)
280
  function scandir($dirstr)
281
  {
281
  {
282
   // php.net/scandir (PHP5)
282
   // php.net/scandir (PHP5)
283
   $files = array();
283
   $files = array();
284
   $fh = opendir($dirstr);
284
   $fh = opendir($dirstr);
285
   while (false !== ($filename = readdir($fh)))
285
   while (false !== ($filename = readdir($fh)))
286
   {
286
   {
287
     array_push($files, $filename);
287
     array_push($files, $filename);
288
   }
288
   }
289
   closedir($fh);
289
   closedir($fh);
290
   return $files;
290
   return $files;
291
  }
291
  }
292
}
292
}
293
?>
293
?>