Results 1 to 3 of 3

Thread: PHP code to copy one folder into another folder

  1. #1
    Join Date
    Feb 2011
    Posts
    22

    PHP code to copy one folder into another folder

    PHP Code:
    <?php
    mkdir("filesscreate",0777);
    copy('admin','filescreate');
    ?>
    This is PHP code to copy the file from existing folder into new folder. I error after executing the program. Please help me out

  2. #2
    Join Date
    Jun 2011
    Posts
    45

    Re: PHP code to copy one folder into another folder

    First you make a directory then set a permission to copy the files. Take a example
    PHP Code:
    <?php
    copydir("admin","filescreate");
    echo "done";

    function copydir($source,$destination)
    {
    if(!is_dir($destination)){
    $oldumask = umask(0);
    mkdir($destination, 01777); // so you get the sticky bit set
    umask($oldumask);
    }
    $dir_handle = @opendir($source) or die("Unable to open");
    while ($file = readdir($dir_handle))
    {
    if($file!="." && $file!=".." && !is_dir("$source/$file"))
    copy("$source/$file","$destination/$file");
    }
    closedir($dir_handle);
    }
    ?>
    In this code I made one SOURCE directory (have permission to read)and another is DESTINATION directory(have permission to write)
    It code filescreate is to be created in the same root directory where ADMIN resides. If you wish to copy filescreate inside another directory then you would have to make sure the directory has permission.

  3. #3
    jhonpaul Guest

    Re: PHP code to copy one folder into another folder

    <?php
    $file = 'example.txt';
    $newfile = 'example.txt.bak';

    if (!copy($file, $newfile)) {
    echo "La copie $file du fichier a échoué...\n";
    }
    ?>
    I tried to copy a file from /tmp to /var/www/html.
    But i always get an permission denied (even after a chmod 0777 to the /var/www/html directory)

    After spending a lot of hours searching for my error, I found it.
    But not where I thought it....It was the turned on SELinux.
    (Fedora 15).So i do a echo 0 >/selinux/enforce and everything works perfect
    &lt;?php

    $from =\\'
    $to=\\'./somefile.zip\\';
    if (!@copy($from,$to)) {
    $errors= error_get_last();
    echo \\&quot;COPY ERROR: \\&quot;.$errors[\\'type\\'];
    echo \\&quot;&lt;br /&gt;\\\\n\\&quot;.$errors[\\'message\\'];
    } else {
    echo \\&quot;File copied from remote!\\&quot;;
    }

Similar Threads

  1. My folder name is too long is not able to copy in windows 7
    By Kandarpa in forum Operating Systems
    Replies: 3
    Last Post: 21-01-2011, 04:29 PM
  2. How to copy a directory or folder
    By Francesca in forum Tips & Tweaks
    Replies: 4
    Last Post: 27-03-2010, 06:36 PM
  3. Copy To Folder... on every File and Folder
    By technika in forum Operating Systems
    Replies: 4
    Last Post: 05-12-2009, 04:16 PM
  4. Replies: 2
    Last Post: 27-02-2009, 01:23 PM
  5. Copy bookmark folder
    By Donald in forum Windows Software
    Replies: 5
    Last Post: 10-02-2009, 12:33 PM

Tags for this Thread

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
  •  
Page generated in 1,713,566,739.19960 seconds with 17 queries