IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Copie récursive de répertoire [Fait]


Sujet :

Langage PHP

  1. #1
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut Copie récursive de répertoire
    Bonjour à tous

    Quelqu'un pourait-il me dire quel fonction utiliser pour copier un répertoire et sont contenu ?

  2. #2
    Membre habitué Avatar de ..:: Atchoum ::..
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    159
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 159
    Points : 156
    Points
    156
    Par défaut
    Salut,


    2 secondes de recherche
    http://fr.php.net/manual/fr/function.copy.php

    Cf le premier Commentaire...

    Merci de rechercher avant de poster
    On ne peut empêcher les vagues, mais on peut apprendre à les surfer...
    http://blog.plopix.net
    http://www.ez-france.org

  3. #3
    Membre expérimenté
    Avatar de Anduriel
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Février 2004
    Messages
    2 290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Février 2004
    Messages : 2 290
    Points : 1 500
    Points
    1 500
    Par défaut
    Un truc: copy() copie aussi le repertoire?
    Il copies bien les fichiers mais va-t-il copier le repertoire avec ou renvoyer false?

  4. #4
    Membre habitué Avatar de ..:: Atchoum ::..
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    159
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 159
    Points : 156
    Points
    156
    Par défaut
    Citation Envoyé par ..:: Atchoum ::..
    Cf le premier Commentaire...
    Function copydirr
    On ne peut empêcher les vagues, mais on peut apprendre à les surfer...
    http://blog.plopix.net
    http://www.ez-france.org

  5. #5
    Membre expérimenté
    Avatar de Anduriel
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Février 2004
    Messages
    2 290
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Février 2004
    Messages : 2 290
    Points : 1 500
    Points
    1 500
    Par défaut
    Ah ok

  6. #6
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Bonjour et merci beaucoup

    Je ne trouve pas copydirr ssur votre lien.

  7. #7
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut


    Fais une recherche "copydirr" sur la page si vraiment tu ne trouve pas

  8. #8
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Sans doute ce code, mais je ne voi pas ou placer le répertoire a copier et la clible:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    function copydirr($fromDir,$toDir,$chmod=0757,$verbose=false)
    /*
       copies everything from directory $fromDir to directory $toDir
       and sets up files mode $chmod
    */
    {
    //* Check for some errors
    $errors=array();
    $messages=array();
    if (!is_writable($toDir))
       $errors[]='target '.$toDir.' is not writable';
    if (!is_dir($toDir))
       $errors[]='target '.$toDir.' is not a directory';
    if (!is_dir($fromDir))
       $errors[]='source '.$fromDir.' is not a directory';
    if (!empty($errors))
       {
       if ($verbose)
           foreach($errors as $err)
               echo '<strong>Error</strong>: '.$err.'<br />';
       return false;
       }
    //*/
    $exceptions=array('.','..');
    //* Processing
    $handle=opendir($fromDir);
    while (false!==($item=readdir($handle)))
       if (!in_array($item,$exceptions))
           {
           //* cleanup for trailing slashes in directories destinations
           $from=str_replace('//','/',$fromDir.'/'.$item);
           $to=str_replace('//','/',$toDir.'/'.$item);
           //*/
           if (is_file($from))
               {
               if (@copy($from,$to))
                   {
                   chmod($to,$chmod);
                   touch($to,filemtime($from)); // to track last modified time
                   $messages[]='File copied from '.$from.' to '.$to;
                   }
               else
                   $errors[]='cannot copy file from '.$from.' to '.$to;
               }
           if (is_dir($from))
               {
               if (@mkdir($to))
                   {
                   chmod($to,$chmod);
                   $messages[]='Directory created: '.$to;
                   }
               else
                   $errors[]='cannot create directory '.$to;
               copydirr($from,$to,$chmod,$verbose);
               }
           }
    closedir($handle);
    //*/
    //* Output
    if ($verbose)
       {
       foreach($errors as $err)
           echo '<strong>Error</strong>: '.$err.'<br />';
       foreach($messages as $msg)
           echo $msg.'<br />';
       }
    //*/
    return true;
    }

  9. #9
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut
    Il y a un exemple pourtant. Appelle la fonction comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <?php
    require('./copydirr.inc.php');
    copydirr('./origine','./destination',0777,true);
    ?>
    Sachant que dans cet exemple, tu dois copier le code de la fonction copydirr tel quel dans un fichier copydirr.inc.php

  10. #10
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Il doit donc y avoir un autre fichier copydirr.inc.php qui contien un autre code ?

  11. #11
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut
    Oui ! C'est toi-meme qui le crée et qui mets dedans la déclaration de la fonction copydirr que tu as copié ci-dessus.

  12. #12
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Donc je vien de créer le fichier copydirr.inc.php avec le code que j'ai cité plus haut, puis j'ai appeler la fonction comme vous me l'avez dit se qui me renvoi une erreur a la ligne 15 du ichier copydirr.inc.php:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    function copydirr($fromDir,$toDir,$chmod=0757,$verbose=false) /* copies everything from directory $fromDir to directory $toDir and sets up files mode $chmod */ { //* Check for some errors $errors=array(); $messages=array(); if (!is_writable($toDir)) $errors[]='target '.$toDir.' is not writable'; if (!is_dir($toDir)) $errors[]='target '.$toDir.' is not a directory'; if (!is_dir($fromDir)) $errors[]='source '.$fromDir.' is not a directory'; if (!empty($errors)) { if ($verbose) foreach($errors as $err) echo 'Error: '.$err.'
    '; return false; } //*/ $exceptions=array('.','..'); //* Processing $handle=opendir($fromDir); while (false!==($item=readdir($handle))) if (!in_array($item,$exceptions)) { //* cleanup for trailing slashes in directories destinations $from=str_replace('//','/',$fromDir.'/'.$item); $to=str_replace('//','/',$toDir.'/'.$item); //*/ if (is_file($from)) { if (@copy($from,$to)) { chmod($to,$chmod); touch($to,filemtime($from)); // to track last modified time $messages[]='File copied from '.$from.' to '.$to; } else $errors[]='cannot copy file from '.$from.' to '.$to; } if (is_dir($from)) { if (@mkdir($to)) { chmod($to,$chmod); $messages[]='Directory created: '.$to; } else $errors[]='cannot create directory '.$to; copydirr($from,$to,$chmod,$verbose); } } closedir($handle); //*/ //* Output if ($verbose) { foreach($errors as $err) echo 'Error: '.$err.'
    '; foreach($messages as $msg) echo $msg.'
    '; } //*/ return true; }
    Fatal error: Call to undefined function: copydirr() in s:\www\copie.php on line 15

  13. #13
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut
    L'erreur est dans copie.php. On peut voir le contenu de ce fichier ?

    copie.php et copydirr.inc.php sont bien dans le même répertoire ?

  14. #14
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Oui les deux fichiers sont bien dans le même répertoire.

    Voici le contenu du fichier copie.php:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <?php 
    	 if (!copy('index.php', 'Ok/index.php')) {
         echo "La copie du fichier index.php n'a pas réussi...\n";
         }
    	 require('copydirr.inc.php'); 
    	 copydirr('Outils','Ok/Outils',0777,true); 
    ?>
    J'ai dabors un code qui copi un seul fichier.

  15. #15
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut
    Je crois qu'il manque les balises PHP dans copydirr.inc.php


  16. #16
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Effectivement je les avait oublier

    Maitenant il n'y a plus le même erreur mais un simple erreur de ciblage qui me dit que 'Ok/Outils' n'est pas valide.

  17. #17
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut
    En fait cette fonction va te copier le contenu du repertoire d'origine dans le répertoire de destination. Il faut donc que les 2 répertoires existent.

  18. #18
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Les deux répertoire existe.
    Mais a savoir les fichiers de copie se trouve dans le répertoire cible par ce que je veut les copier eux aussi dans la fouler, voici le code exat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <?php 
        if (!copy('index.php', '../Ok/index.php')) { 
         echo "La copie du fichier index.php n'a pas réussi...\n"; 
         } 
        require('copydirr.inc.php'); 
        copydirr('../Outils','../Ok/Outils',0777,true); 
    ?>
    Voici l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ../Ok/Outils' is not writable
    Penssez vous que cela pose un problème ?

  19. #19
    Membre averti
    Avatar de ghostdogpr
    Étudiant
    Inscrit en
    Octobre 2003
    Messages
    198
    Détails du profil
    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2003
    Messages : 198
    Points : 354
    Points
    354
    Par défaut
    3 possibilités :
    - le dossier n'existe pas
    - le dossier n'est pas à l'adresse indiquée (ce ne serait pas ./ au lieu de ../ ?)
    - le dossier n'a pas les droits en écriture

  20. #20
    Inactif
    Profil pro
    Inscrit en
    Août 2005
    Messages
    1 054
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 1 054
    Points : 340
    Points
    340
    Par défaut
    Si je ne mais qu'un seul point s'est encore pire.

    Est le chmod 0777 qu'il y a dans la command eque fait-il ?

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Réponses: 4
    Dernier message: 21/01/2013, 12h54
  2. Copie récursive et sous répertoires
    Par viewtifulced dans le forum Administration système
    Réponses: 2
    Dernier message: 16/02/2009, 15h54
  3. copie récursive répertoire
    Par hisy dans le forum Langage
    Réponses: 4
    Dernier message: 16/03/2007, 08h40
  4. Copie récursive d'un répertoire
    Par narmataru dans le forum Entrée/Sortie
    Réponses: 2
    Dernier message: 11/09/2006, 18h06
  5. Fonctions permettant la copie d'un répertoire
    Par benj63 dans le forum C++Builder
    Réponses: 6
    Dernier message: 17/06/2004, 08h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo