SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: curl problem

  1. #1
    SitePoint Addict Kevinslair's Avatar
    Join Date
    Jul 2002
    Location
    Binghamton
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    curl problem

    Hi,
    I'm having a problem getting a curl to work on a thumbnail script I have.

    PHP Code:
    <?php
         
        $domain 
    $_SERVER['HTTP_HOST'];

        
    $fullimageurl "http://$domain/images/BCANFALL.JPG";
        
    $fullimageurl2 "http://$domain/images/noimagefound.jpg";

        
    $c curl_init($fullimageurl);
        if (
    curl_getinfo($cCURLINFO_HTTP_CODE) === 200) {
        
    $imagesurl $fullimageurl;
        } elseif (
    curl_getinfo($cCURLINFO_HTTP_CODE) === 404) {
        
    $imagesurl $fullimageurl2;
        } else{
        
    $imagesurl $fullimageurl2;
        }
        
    curl_close($c);

    ?>
    The problem is that the fullimageurl does not exist and should error with the 404 above, but it doesn't. All the other files that do exist come up under the else and not under the 200 OK part. I have no clue what I am doing wrong and see no error with the above.

    Thanks,
    Kevin
    I PHP!

  2. #2
    SitePoint Enthusiast webdesignhouston's Avatar
    Join Date
    Dec 2010
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to call curl_exec before you can call curl_getinfo. Also, before calling curl_exec, you must set CURLOPT_RETURNTRANSFER to true otherwise curl_exec will write the image's binary data (or the content of the 404 page) directly to the browser.

    PHP Code:
    <?php
        $domain 
    $_SERVER['HTTP_HOST'];
        
    $fullimageurl "http://$domain/images/BCANFALL.JPG";
        
    $fullimageurl2 "http://$domain/images/noimagefound.jpg";
        
    $c curl_init($fullimageurl);
        
    curl_setopt($cCURLOPT_RETURNTRANSFERtrue);
        
    curl_exec($c);
        
    $http_code curl_getinfo($cCURLINFO_HTTP_CODE);
        
    curl_close($c);
        
    var_dump($http_code);
    ?>

  3. #3
    SitePoint Addict Kevinslair's Avatar
    Join Date
    Jul 2002
    Location
    Binghamton
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a million!
    Trying it now!
    I PHP!

  4. #4
    SitePoint Addict Kevinslair's Avatar
    Join Date
    Jul 2002
    Location
    Binghamton
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    100% what I was looking for!!!! Thanks!
    I PHP!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •