SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    copying contents of folders to another

    Hi guys. This is the script I am using to move files from one folder to another.

    PHP Code:
    $foldername=$_POST['foldername'];
    if(!
    file_exists($foldername)) {
     
    mkdir("$foldername/"0777); 
    }
    $source '../files';

    $dest"$foldername";




    $handle opendir($source);



    // Loop through all files in dir

    while (false !== ($file readdir($handle))) {

        
    copy($file$dest '/' $file);

    }



    closedir($handle); 




    The issue is it moves all the files over fine but the folders dont get moved over


    What could cause this?


    Regards


    Chris

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi Chris,

    You need to recursively iterate the folder structure, check out this example.

    Anthony.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •