Jump to content

Copy to certain directory..


teongkia

Recommended Posts

Hi i try make a program to copy the files from 1 fixed directory to another directory which i can choose it by input fied such as D:\PeterSim\def

[code]html>
<form method="POST">
<p>folder Name: <input type="text" name="folder" /></p>
<p><input type="submit" value="ok"/></p>
</form>
</html>

<?php
$folder=$_POST['folder'];

$num = dircopy('D:\PeterSim\abc', '$folder', 1);

function dircopy($srcdir, $dstdir, $verbose = false) {
  $num = 0;
  if(!is_dir($dstdir)) mkdir($dstdir);
  if($curdir = opendir($srcdir)) {
  while($file = readdir($curdir)) {
    if($file != '.' && $file != '..') {
      $srcfile = $srcdir . '\\' . $file;
      $dstfile = $dstdir . '\\' . $file;
      if(is_file($srcfile)) {
        if(is_file($dstfile)) $ow = filemtime($srcfile) - filemtime($dstfile); else $ow = 1;
        if($ow > 0) {
          if($verbose) echo "Copying '$srcfile' to '$dstfile'...";
          if(copy($srcfile, $dstfile)) {
            touch($dstfile, filemtime($srcfile)); $num++;
            if($verbose) echo "OK\n";
          }
          else echo "Error: File '$srcfile' could not be copied!\n";
        }                 
      }
      else if(is_dir($srcfile)) {
        $num += dircopy($srcfile, $dstfile, $verbose);
      }
    }
  }
  closedir($curdir);
  }
  return $num;
}

?>[/code]

When i type in D:\PeterSim\def and click ok,nothing is copied.May i know what is the problem?Thanks.
Link to comment
https://forums.phpfreaks.com/topic/31063-copy-to-certain-directory/
Share on other sites

Hi actually i want to make a program using php which let me type in the destination path such as D:\PeterSim\def which i do not need to change the destination path inside the code but just type it in the input for the submit form.Do you have any idea to do it?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.