curl error detection

Discussion in 'PHP' started by stats, Sep 21, 2007.

  1. #1
    Hi guys

    i am getting a file trough CURL and want to put up some kind of a success indicator to show if the file has been successfully downloaded or not

    here's my CURL logic

    $ch = curl_init("http://www.domain.com/getthis.zip");
    $fp = fopen("savehere.zip", "w");
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    PHP:
    now i want to put something like
    if (success_logic_here) {
    $success = 1;
    }
    PHP:
    in the middle of this code ..

    I know that i could have written something like
    if (file_exists("savehere.zip")) { $success = 1;}
    PHP:
    but thats a kind of ugly way to do it .. why torture the file system if there's possibility to just check on CURL ..

    so which part of the CURL determines if it's successfull or not ?

    Thanks
     
    stats, Sep 21, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    nico_swd, Sep 21, 2007 IP
  3. stats

    stats Well-Known Member

    Messages:
    586
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    seems a good idea the curl_error()

    any idea if that should be BEFORE or AFTER the curl_close($ch); ?
     
    stats, Sep 21, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Before. The cURL handle variable will be unset with curl_close(), and you need it for both of the functions above.
     
    nico_swd, Sep 21, 2007 IP