| 808 | | |
| | 808 | /* filesystem methods */ |
| | 809 | /* copy_files {{{ */ |
| | 810 | /** |
| | 811 | * Copies files and directories recursive to dirs under site_images |
| | 812 | * |
| | 813 | * @param string $src The sourcefile or dir |
| | 814 | * @param string $dst The dir inside site_images where the files/folders should be copied to |
| | 815 | * @param int $overwrite_dest if set will overwrite the destination if it already exists |
| | 816 | */ |
| | 817 | public function copy_files($srcbase, $src, $dest, $overwrite_dest = 0) { |
| | 818 | // calculate where the site_images dir is |
| | 819 | $basepath = realpath(dirname(__FILE__)."/../site_images/"); |
| | 820 | $dst = sprintf("%s/%s", $basepath, $dest); |
| | 821 | //check if the dst dir is there |
| | 822 | if (!is_dir($dst)) |
| | 823 | if (!mkdir($dst)) |
| | 824 | die("could not create directory $dst"); |
| | 825 | if ($handle = opendir(sprintf("%s/%s", $srcbase, $src))) { //open source directory |
| | 826 | while (false !== ($file = readdir($handle))) { //loop through all items in the opened source dir |
| | 827 | if ($file != "." && $file != "..") { //we wont copy the special 'current dir' and 'one dir up' items |
| | 828 | if ($src) |
| | 829 | $path = sprintf("%s/%s", $src, $file); |
| | 830 | else |
| | 831 | $path = $file; |
| | 832 | $s = sprintf("%s/%s", $srcbase, $path); |
| | 833 | $d = sprintf("%s/%s", $dst, $path); |
| | 834 | if (is_file($s)) { |
| | 835 | if (is_file($d) || $overwrite_dest) { |
| | 836 | if (!copy($s, $d)) |
| | 837 | echo "Something went wrong while trying to copy $s to $d<br>"; |
| | 838 | } |
| | 839 | } elseif (is_dir($s)) { |
| | 840 | if (!is_dir($d)) |
| | 841 | if (!mkdir($d)) |
| | 842 | echo "Something went wrong while trying to create dir $d<br>\n"; |
| | 843 | $this->copy_files($srcbase, $path, $dest, 1); |
| | 844 | } |
| | 845 | } |
| | 846 | } |
| | 847 | closedir($handle); |
| | 848 | } |
| | 849 | } |
| | 850 | /* }}} */ |