teongkia Posted December 18, 2006 Share Posted December 18, 2006 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 More sharing options...
btherl Posted December 18, 2006 Share Posted December 18, 2006 Add some more "else" statements, to see what is failing. Currently you're not checking for failure of opendir(). If all your system calls are succeeding but nothing is happening, then it's time to start worrying :) Link to comment https://forums.phpfreaks.com/topic/31063-copy-to-certain-directory/#findComment-143429 Share on other sites More sharing options...
teongkia Posted December 18, 2006 Author Share Posted December 18, 2006 I think the main problem is the $folder.It can't read the value i enter in input such as D:\PeterSim\def.Maybe the problem is the '\'.Do you have any idea with it?thanks. Link to comment https://forums.phpfreaks.com/topic/31063-copy-to-certain-directory/#findComment-143438 Share on other sites More sharing options...
btherl Posted December 18, 2006 Share Posted December 18, 2006 It could be that. Try using stripslashes() on the input to remove any extra backslashes. And print out the values before and after so you can see if it worked properly. Link to comment https://forums.phpfreaks.com/topic/31063-copy-to-certain-directory/#findComment-143440 Share on other sites More sharing options...
teongkia Posted December 18, 2006 Author Share Posted December 18, 2006 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? Link to comment https://forums.phpfreaks.com/topic/31063-copy-to-certain-directory/#findComment-143452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.