Subversion Repositories Applications.papyrus

Rev

Rev 71 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 71 Rev 74
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 Lesser General Public                                           |
9
// | modify it under the terms of the GNU Lesser 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
// | Lesser General Public License for more details.                                                      |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
18
// | You should have received a copy of the GNU Lesser 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: FIC_manipulation.fonct.php,v 1.2 2004-10-18 10:12:22 jpm Exp $
22
// CVS : $Id: FIC_manipulation.fonct.php,v 1.3 2004-10-19 15:57:03 jpm Exp $
23
/**
23
/**
24
* Bibliothèque de fonctions permettant de manipuler des fichier ou des dossiers.
24
* Bibliothèque de fonctions permettant de manipuler des fichier ou des dossiers.
25
*
25
*
26
* Contient des fonctions permettant de manipuler des fichier ou des dossiers.
26
* Contient des fonctions permettant de manipuler des fichier ou des dossiers.
27
*
27
*
28
*@package Fichier
28
*@package Fichier
29
//Auteur original :
29
//Auteur original :
30
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
30
*@author        Jean-Pascal MILCENT <jpm@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.2 $ $Date: 2004-10-18 10:12:22 $
34
*@version       $Revision: 1.3 $ $Date: 2004-10-19 15:57:03 $
35
// +------------------------------------------------------------------------------------------------------+
35
// +------------------------------------------------------------------------------------------------------+
36
*/
36
*/
37
 
37
 
38
// +------------------------------------------------------------------------------------------------------+
38
// +------------------------------------------------------------------------------------------------------+
39
// |                                           LISTE de FONCTIONS                                         |
39
// |                                           LISTE de FONCTIONS                                         |
40
// +------------------------------------------------------------------------------------------------------+
40
// +------------------------------------------------------------------------------------------------------+
41
 
41
 
42
/**
42
/**
43
* Fonction supprimerDossier() - Supprime un fichier ou un dossier et tout son contenu.
43
* Fonction supprimerDossier() - Supprime un fichier ou un dossier et tout son contenu.
44
*
44
*
45
* Fonction récursive supprimant tout le contenu d'un dossier.
45
* Fonction récursive supprimant tout le contenu d'un dossier.
46
* Auteur d'origine : Aidan Lister (http://aidan.dotgeek.org/lib/?file=function.rmdirr.php)
46
* Auteur d'origine : Aidan Lister (http://aidan.dotgeek.org/lib/?file=function.rmdirr.php)
47
* Traduction française et ajout gestion séparateur : Jean-Pascal Milcent
47
* Traduction française et ajout gestion séparateur : Jean-Pascal Milcent
48
*
48
*
49
* @author      Aidan Lister <aidan@php.net>
49
* @author      Aidan Lister <aidan@php.net>
50
* @author      Jean-Pascal Milcent <jpm@tela-botanica.org>
50
* @author      Jean-Pascal Milcent <jpm@tela-botanica.org>
51
* @version     1.0.0
51
* @version     1.0.0
52
* @param       string   le chemin du dossier à supprimer.
52
* @param       string   le chemin du dossier à supprimer.
53
* @param       string   le caractère représentant le séparateur dans un chemin d'accès.
53
* @param       string   le caractère représentant le séparateur dans un chemin d'accès.
54
* @return      bool     retoure true en cas de succès, false dans le cas contraire.
54
* @return      bool     retoure TRUE en cas de succès, FALSE dans le cas contraire.
55
*/
55
*/
56
function supprimerDossier($dossier_nom, $separateur)
56
function supprimerDossier($dossier_nom, $separateur = '/')
57
{
57
{
58
    // Simple suppression d'un fichier
58
    // Simple suppression d'un fichier
59
    if (is_file($dossier_nom)) {
59
    if (is_file($dossier_nom)) {
60
        return unlink($dossier_nom);
60
        return unlink($dossier_nom);
61
    }
61
    }
-
 
62
    
62
    
63
    if (is_dir($dossier_nom)) {
63
    // Analyse du dossier
64
        // Analyse du dossier
64
    $dossier = dir($dossier_nom);
65
        $dossier = dir($dossier_nom);
65
    while (false !== $entree = $dossier->read()) {
66
        while (false !== $entree = $dossier->read()) {
66
        // Nous sautons les pointeurs
67
            // Nous sautons les pointeurs
67
        if ($entree == '.' || $entree == '..') {
68
            if ($entree == '.' || $entree == '..') {
-
 
69
                continue;
-
 
70
            }
-
 
71
            
-
 
72
            // Suppression du dossier ou appel récursif de la fonction
-
 
73
            if (is_dir($dossier_nom.$separateur.$entree)) {
-
 
74
                supprimerDossier($dossier_nom.$separateur.$entree, $separateur);
-
 
75
            } else {
-
 
76
                unlink($dossier_nom.$separateur.$entree);
68
            continue;
77
            }
-
 
78
        }
-
 
79
        // Nettoyage
-
 
80
        $dossier->close();
-
 
81
        return rmdir($dossier_nom);
-
 
82
    } else {
-
 
83
        return false;
-
 
84
    }
69
        }
85
}
-
 
86
 
70
        
87
/**
-
 
88
* Fonction creerDossier() - Créer une structure de dossier.
-
 
89
*
-
 
90
* Fonction récursive créant une structure de dossiers.
-
 
91
* Auteur d'origine : Aidan Lister (http://aidan.dotgeek.org/lib/?file=function.mkdirr.php)
-
 
92
* Traduction française et ajout gestion séparateur : Jean-Pascal Milcent
-
 
93
*
-
 
94
* @author      Aidan Lister <aidan@php.net>
-
 
95
* @version     1.0.0
-
 
96
* @param       string   la structure de dossier à créer.
-
 
97
* @param       string   le mode de création du répertoire.
-
 
98
* @param       string   le caractère représentant le séparateur dans un chemin d'accès.
-
 
99
* @return      bool     retourne TRUE en cas de succès, FALSE dans le cas contraire.
-
 
100
*/
-
 
101
 
-
 
102
function creerDossier($chemin, $mode = null, $separateur = '/')
-
 
103
{
71
        // Suppression du dossier ou appel récursif de la fonction
104
    // Check if directory already exists
-
 
105
    if (is_dir($chemin) || empty($chemin)) {
-
 
106
        return true;
-
 
107
    }
-
 
108
    
-
 
109
    // Ensure a file does not already exist with the same name
72
        if (is_dir($dossier_nom.$separateur.$entree)) {
110
    if (is_file($chemin)) {
73
            supprimerDossier($dossier_nom.$separateur.$entree);
111
        trigger_error('mkdirr() File exists', E_USER_WARNING);
-
 
112
        return false;
-
 
113
    }
-
 
114
    
-
 
115
    // Crawl up the directory tree
-
 
116
    $chemin_suite = substr($chemin, 0, strrpos($chemin, $separateur));
-
 
117
    if (creerDossier($chemin_suite, $mode, $separateur)) {
74
        } else {
118
        if (!file_exists($chemin)) {
75
            unlink($dossier_nom.$separateur.$entree);
119
            return @mkdir($chemin, $mode);
76
        }
120
        }
77
    }
121
    }
78
    
122
    
79
    // Nettoyage
-
 
80
    $dossier->close();
-
 
81
    return rmdir($dossier_nom);
123
    return false;
82
}
124
}
83
 
125
 
84
/* +--Fin du code ----------------------------------------------------------------------------------------+
126
/* +--Fin du code ----------------------------------------------------------------------------------------+
85
*
127
*
86
* $Log: not supported by cvs2svn $
128
* $Log: not supported by cvs2svn $
-
 
129
* Revision 1.2  2004/10/18 10:12:22  jpm
-
 
130
* Traduction commentaires...
-
 
131
*
87
* Revision 1.1  2004/10/18 10:09:12  jpm
132
* Revision 1.1  2004/10/18 10:09:12  jpm
88
* Ajout d'une fonction permettant de supprimer récursivement un répertoire.
133
* Ajout d'une fonction permettant de supprimer récursivement un répertoire.
89
*
134
*
90
*
135
*
91
* +-- Fin du code ----------------------------------------------------------------------------------------+
136
* +-- Fin du code ----------------------------------------------------------------------------------------+
92
*/
137
*/
93
?>
138
?>