php directory copy help urgently needed

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
a little help please.....!!!!
consider i ve got a directory "mydata"in the www directory
i want a script which can copy that ("mydata") directory when i use this html form below...
Code:
<form action=somepage.php>
<input type=text name=userinput>
<input type=submit>
</form>
when i hit the submit button the directory "mydata" should be copied.with all its files
.... to a new name as typed by the user
if the name of the directory already exists it must return an error saying "already copied" n must not overwrite the files ..and if the name of the dir. doesnt exists the dir. must be copied acc to the user input and must echo "dir c0py successfull"
reference: http://php.net/copy
ill pay you 200 credits for the script the above task


and also tell me how do i echo the name of the directory in which a php page resides
for ex: page.php is in the folder"xyz" so i want it to escho the name of the folder xyz
i tried this echo"./$dir"; but it did not work .....any guesses
 
Last edited:

nightscream

New Member
Messages
948
Reaction score
0
Points
0
this should do the trick.

PHP:
<?
$dir = "mydata";
$newdir = $_POST['dirname'];

if(is_dir($newdir)) {
    echo 'already copied';
    exit;
}else {
    mkdir($newdir);
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) { 
            $files .= " ".$file;
        }
        $files = explode(" ", $files);

        unset($files[0]);
        unset($files[1]);
        unset($files[2]);
        unset($files[3]);

        $file = implode(" ", $files);
        $files = explode(" ", $file);

        closedir($handle); 
    }

    $arrayLen = sizeof($files);
    for($i = 0; $i < $arrayLen; $i++) {
        if(copy($dir."/".$files[$i], $newdir."/".$files[$i])) {
            $msg = "dir c0py successfull";
        }else {
            $msg = "dir c0py failed";
        }
    }
    echo $msg;
    
}
?>
 
Last edited:

nahsorhseda

Member
Messages
116
Reaction score
0
Points
16
the whole folder got copied successfully but ...iam getting this error can you solve it

PHP:
Warning:  copy() [function.copy]: The first argument to copy() function cannot be a directory in /home/hsedan/public_html/page.php on line 29

Warning:  copy() [function.copy]: The first argument to copy() function cannot be a directory in /home/hsedan/public_html/page.php on line 29
dir c0py successfull

at the end you can 'see dir copy successfull " the script works but i want to avoid the error

here is line 29
PHP:
if(copy($dir."/".$files[$i], $newdir."/".$files[$i])) {

if you solve this 200 credits are all yours

and also tell me how do i echo the name of the directory in which a php page resides
for ex: page.php is in the folder"xyz" so i want it to escho the name of the folder xyz
i tried this echo"./$dir"; but it did not work .....any guesses
Edit:
oh man i got it right i had seen this somewhere before so what i did was just added an "@"
now here is line 29 with "@"
PHP:
if(@copy($dir."/".$files[$i], $newdir."/".$files[$i])) {

ill give your 200 credits ......man iam really happy right now
can please solve this issue too


tell me how do i echo the name of the directory in which a php page resides
for ex: page.php is in the folder"xyz" so i want it to echo the name of the folder xyz
i tried this echo"./$dir"; but it did not work .....any guesses more 25 credits for this
 
Last edited:

nightscream

New Member
Messages
948
Reaction score
0
Points
0
can I see your form script?
mmh I tested it on my localhost and it worked.. :s

I'm going to think about your second question..
It has to be
Code:
<form action="somepage.php" method="post" enctype="multipart/form-data">
<input type="text" name="dirname">
<input type="submit">
</form>
Ok i have read it right, problem was fixed :p
I'll look in the other issue later, I'm going away for some hours.
when do you want it showed?
 
Last edited:
Top