Downloading a file from http url

Discussion in 'PHP' started by mancade, Nov 22, 2007.

  1. #1
    Hi,

    I'm trying to download a file from a http page that requires user authentication. The file can be downloaded manually by clicking on the link. I would like to do this automatically using a PHP script.

    Here's the code I am using:

    $srcFilePath = "http://username:password@www.mydomain.com//filename.txt ";

    $desFilePath = "filename.txt";

    if (!copy($srcFilePath, $desFilePath)) {
    echo "failed to copy $file...\n";

    I get the following error with the above code:

    Warning: copy(http://username:password@www.mydomain.com//filename.txt) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /…/ADETEST/ADETEST3.PHP on line 27

    Thanks in advance

    Ade
     
    mancade, Nov 22, 2007 IP
  2. jammu143

    jammu143 Banned

    Messages:
    167
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    there is double slah befire file .txt
     
    jammu143, Nov 22, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Are you trying to download the file via http or ftp (you seem to be doing ftp, using http protocol)?

    Peace,
     
    Barti1987, Nov 22, 2007 IP
  4. mancade

    mancade Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your responses...

    I'm trying to download the file via http. How do I download via http?

    Replacing double slash with single slash makes no difference.
     
    mancade, Nov 22, 2007 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Barti1987, Nov 22, 2007 IP
  6. mancade

    mancade Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6

    Thanks for your response.

    I have tried the code in the suggested link. A file is created but it has a size of 0KB, and is empty. Any suggestions?
     
    mancade, Nov 23, 2007 IP
  7. chandubhai

    chandubhai Banned

    Messages:
    556
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Can you please paste the code as code?
     
    chandubhai, Nov 23, 2007 IP
  8. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #8
    " failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request "
    " A file is created but it has a size of 0KB "

    Are you sure the file your grabbing both exists and hasn't got anything blocking you from accessing it. Whats the file you're trying to grab.
     
    Danltn, Nov 23, 2007 IP
  9. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #9
    maybe ur server doesnt support external copy function
     
    PowerExtreme, Nov 23, 2007 IP