+ Reply to Thread
Results 1 to 7 of 7

Thread: php directory copy help urgently needed

  1. #1
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Question php directory copy help urgently needed

    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 by nahsorhseda; 12-13-2007 at 02:07 AM. Reason: forgot ot mention reference
    glad to resolve problems in c++ n php

  2. #2
    nightscream is offline x10 Lieutenant nightscream is an unknown quantity at this point
    Join Date
    Feb 2006
    Location
    Hallaar, Belgium
    Posts
    474

    Re: php directory copy help urgently needed

    does it contains subfolders?
    ------------------------------------------------------------------------------------------
    If you have any troubles with a website or a script, just send me a pm.

    I also code websites in xHTML/css, can code javascript and php too if needed

  3. #3
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: php directory copy help urgently needed

    no it doesnt have any subfolders .it has only php,css and image files thats all
    glad to resolve problems in c++ n php

  4. #4
    nightscream is offline x10 Lieutenant nightscream is an unknown quantity at this point
    Join Date
    Feb 2006
    Location
    Hallaar, Belgium
    Posts
    474

    Re: php directory copy help urgently needed

    this should do the trick.

    PHP Code:
    <?
    $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 by nightscream; 12-14-2007 at 04:56 AM.
    ------------------------------------------------------------------------------------------
    If you have any troubles with a website or a script, just send me a pm.

    I also code websites in xHTML/css, can code javascript and php too if needed

  5. #5
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: php directory copy help urgently needed

    the whole folder got copied successfully but ...iam getting this error can you solve it

    PHP Code:
    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 Code:
    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 Code:
    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 by nahsorhseda; 12-14-2007 at 05:55 AM. Reason: Automerged Doublepost
    glad to resolve problems in c++ n php

  6. #6
    nightscream is offline x10 Lieutenant nightscream is an unknown quantity at this point
    Join Date
    Feb 2006
    Location
    Hallaar, Belgium
    Posts
    474

    Re: php directory copy help urgently needed

    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 by nightscream; 12-14-2007 at 06:26 AM.
    ------------------------------------------------------------------------------------------
    If you have any troubles with a website or a script, just send me a pm.

    I also code websites in xHTML/css, can code javascript and php too if needed

  7. #7
    nahsorhseda's Avatar
    nahsorhseda is offline x10 Sophmore nahsorhseda is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    mumbai
    Posts
    116

    Re: php directory copy help urgently needed

    no thanks guys i got it already
    glad to resolve problems in c++ n php

+ Reply to Thread

Similar Threads

  1. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  2. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  3. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  4. Help with PHP is needed...
    By dragoneye_xp in forum Scripts & 3rd Party Apps
    Replies: 3
    Last Post: 06-17-2006, 10:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers