Why can't I get image?

Discussion in 'PHP' started by Sleeping Troll, Jun 6, 2009.

  1. #1
    Here is my code(although I have tried a miriad of variations):
    <?php 
    $ch = curl_init(); 
    $timeout = 0; // set to zero for no timeout 
    curl_setopt ($ch, CURLOPT_URL, "http://twitter.com/statuses/public_timeline.json"); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    $twitter = curl_exec($ch); 
    curl_close($ch); 
    $twitterArray = json_decode($twitter);  
    foreach ($twitterArray as $tweet){ 
            $i++; 
        $user = $tweet->user;  
        $id[$i] = $user->id; 
            $imageURL[$i] = "\"".$user->profile_image_url."\"";  
        $url[$i] = $user->url; 
            $name[$i] = $user->screen_name;  
        $description[$i] = $user->description;  
        $created[$i] = $user->created_at;  
        $followers[$i] = $user->followers_count;  
        $friends[$i] = $user->friends_count; 
             
        echo(" 
                <pre> 
    Record #: $i<br>  
           Image:                $image[$i]<br> 
           URL:                $url[$i]<br>  
           Name:                $name[$i]<br> 
           Description:            $description[$i]<br>  
           Created on:            $created[$i]<br>  
           Followers:            $followers[$i]<br>  
           Friends:                $friends[$i]<br><br> 
                </pre> 
        ");  
                $ch = curl_init(); 
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
                curl_setopt ($ch, CURLOPT_BINARYTRANSFER, 1); 
                curl_setopt ($ch, CURLOPT_URL,$imageURL[$i]); 
                curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 60); 
                $imageData = curl_exec($ch); 
              echo 'image is: ', htmlentities(substr($imageData, 0, 4)), "...<br />\n"; 
                curl_close($ch); 
                $image = imagecreatefromstring($imageData); 
                $Orbimage = "images/twitter/".$id[$i].".png"; 
                $Orbback = imagecreatefrompng("../images/main/OrbBack.png"); 
                list($current_width, $current_height) = getimagesize($twitterImage); 
                $Orbfront = imagecreatefrompng("../images/main/OrbFront.png"); 
                imagecopy($Orbback,$imageData,50,50,$current_width/2,$current_height/2,$current_width,$current_height); 
                imagecopy($Orbback,$Orbfront,0,0,0,0,100,100); 
                imagesavealpha($Orbback, true); 
                imagepng($Orbback,$Orbimage); 
    } 
    
    ?> 
    PHP:
    here is the url: http://orbzorbz.com/php/twitterData.php

    I am lost, have tried file_get_contents(url) with no luck and yes I have configured php to allow file open. ???
    P.S. the string is indeed empty, even though i get no "cannot open url" error. I can enter url in browser and display image however!
    So I guess the real question is why is it empty? I have put in an html "echo" to display pic, it works just fine, of course that is client side.
     
    Sleeping Troll, Jun 6, 2009 IP
  2. alfa_375

    alfa_375 Active Member

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Hi,

    Can you post the description of user table and check whether this line is contain anything or not.

    $url[$i] = $user->url;

    Regards,
    Amer
     
    alfa_375, Jun 6, 2009 IP
  3. JDevereux

    JDevereux Peon

    Messages:
    50
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    change $imageURL[$i] = "\"".$user->profile_image_url."\""; to:

    $imageURL[$i] = $user->profile_image_url;

    It's already a string so you don't need to add quotes.

    You might also want to look at this article.
     
    JDevereux, Jun 6, 2009 IP