copy function

Discussion in 'PHP' started by cris02, Mar 13, 2006.

  1. #1
    is it posible to copy the file in the web servergoing to my local computer? instead of downloading it. example:
    copy('http://some.com/file.txt', 'c:\file.txt');
    PHP:

     
    cris02, Mar 13, 2006 IP
  2. adstracker

    adstracker Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No, I don't think that's possible.
    You will need to download the file first, put it in a variable, and then copy it to your pc.
    Im not sure if php has a download function, but if they have, you can probably point to the download directory in one step, and you wouldn't need to use the buffer.
     
    adstracker, Mar 13, 2006 IP
  3. Canada Web Design

    Canada Web Design Active Member

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #3
    looks like a nice little virus to me :) no its not possible php will only execute server side.
     
    Canada Web Design, Mar 13, 2006 IP
  4. adstracker

    adstracker Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Indeed, so if you really want to use this server-side, then it's possible.
     
    adstracker, Mar 13, 2006 IP
  5. cris02

    cris02 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    yeah virus like, but that is not my intension, i'm just want to mirroring the my site which my file stored then going to my intranet program. to be automatically copy the file in someones folder. if they posible i want drag and drop basis. :p
     
    cris02, Mar 13, 2006 IP
  6. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The following php code should do the trick:

    
    $url ="www.TARGETDOMAIN.com";
    $page = "/page.html";
    $fp = fsockopen("$url", 80, $errno, $errstr, 30);
    if (!$fp) {
       echo "$errstr ($errno)<br />\n";
    } else {
       $out = "GET $page HTTP/1.0\r\n";
       $out .= "Host: $url\r\n";
       $out .= "Connection: Close\r\n\r\n";
    
       fwrite($fp, $out);
       while (!feof($fp)) {
           $printThis .= fgets($fp, 128);
       }
       fclose($fp);
    }
    echo $printThis;
    $handle = fopen( "copy.html", "w");
    fwrite( $handle, $printThis);
    
    Code (markup):
     
    clancey, Mar 14, 2006 IP
  7. MikeB

    MikeB Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Ok thanks.
    But you can make something like this - copy a file from pc to server ?
     
    MikeB, Apr 24, 2006 IP