Copy command error in term project

Discussion in 'PHP' started by akshaygupta5555, May 6, 2009.

  1. #1
    Here is a small code which I want to run .

    <?php

    $url="http://www.domaintools.com/msn.com";
    copy ($url,"c://misc.txt");

    ?>

    Error

    Warning: copy(http://www.domaintools.com/msn.com) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in PHPDocument1 on line 4

    Help me
     
    akshaygupta5555, May 6, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    You can't open a remote file using this.

    You could use something like file_get_contents to get the page and then file_put_contents (or fwrite) to write it to a text file.
     
    jestep, May 6, 2009 IP
  3. gabrola

    gabrola Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #3
    This can't work, here's one of the methods how you can do it.
    
    <?php
    $file = file_get_contents("http://www.domaintools.com/msn.com");
    $fp = fopen("c://misc.txt", "w+");
    fwrite($fp, $file);
    fclose($fp);
    ?>
    
    PHP:
     
    gabrola, May 6, 2009 IP