Picture Grabber

Discussion in 'PHP' started by lllpumaslll, Oct 1, 2007.

  1. #1
    I need to fix this code so that it matches myspace.com new path for the default images.

    This is my code (which was working fine, until myspace changed the path):
    <?php
    
    class socket
    {
    	function GetFromMyspace($friend_id)
    	{
    		$full_file_path = MYSPACE_PROFILE_PATH.$friend_id;
    
    		$handle = fopen($full_file_path,"r");
    		if (!$handle)
    		{
        		echo "<p>Unable to open remote file.\n";
        		$arr = 0;
    		}
    		else
    		{
    			$timeout = 300;
    			//$old = ini_set('default_socket_timeout', $timeout);
    			//	ini_set('default_socket_timeout', $old);
    			//stream_set_timeout($handle, $timeout);
    			//stream_set_blocking($handle, 0);
    			//	set_time_limit(120);
    			ini_set('max_execution_time','120');
    			set_time_limit(120);
    			ini_set('default_socket_timeout','120');
    			while($contents = fread($handle,'1024'))
    			{
    				$buff .= $contents;
    			}
    
    			//echo "buff--> = ".$buff."--------->";
    
    			preg_match("/<a id=\"ctl00_Main_ctl00_UserBasicInformation1_hlDefaultImage\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$friend_id\">.*?<img src=\"(.*?)\"><\/a\>/is",$buff,$match);
    
    			$string_ahref = $match[0];
    			//echo "string = ".$string_ahref;
    
    
    			$substr = substr($string_ahref,0,350);
    
    			$trimed = strip_tags($substr,"<img>");
    			$trimed = trim($trimed);
    			//echo "strip".$trimed;
    
    			$len = strlen($trimed);
    			//echo "length".$len."<br>";
    			$image_name = substr($trimed,10,($len-25));
    			//echo "<br><br>imname= '".$image_name."'<br>";
    
    			preg_match("/<span class=\"nametext\".*>?<\/span>/is",$buff,$match_name);
    
    			//echo "name= ".$match_name[0];
    
    			if(empty($image_name))
    			{
    				$img_name = substr($match_name[0],100,600);
    				$img  = strip_tags($img_name,"<img>");
    
    				//echo "strip-->".$img."<--";
    				$img = trim($img);
    
    
    				$len = strlen($img);
    				//echo "length".$len."<br>";
    
    				$image_name = substr($img,10,($len-25));
    
    				$image_name = trim($image_name);
    				//echo "ooo".$img."000";
    				//echo "Image = ->".$image_name."<--";
    			}
    
    			//echo "<br><br>imname= '".$image_name."'<br>";
    
    			if(substr($image_name,0,10)=="<img src=\"")
    			{
    				$third_name = substr($image_name,10,strlen($image_name));
    				//echo "third = ".$third_name;
    				$image_name = $third_name;
    			}
    
    			//echo "<br><br>imname= '".$image_name."'<br>";
    			$subname    = substr($match_name[0],0,200);
    			$name       = strip_tags($subname,"<span>");
    			$name = trim($name);
    
    			$len_name   = strlen($name);
    		//	echo $len_name;
    			$name_final = substr($name,23,($len_name-30));
    
    			$arr = array("name"=>$name_final,"imagepath"=>$image_name);
    
    			//exit();
    		}
    		fclose($handle);
    		ini_restore('max_execution_time');
    		ini_restore('default_socket_timeout');
    		return $arr;
    
    	}
    }
    
    ?>
    Code (markup):

     
    lllpumaslll, Oct 1, 2007 IP
  2. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    whats wrong to the code?
     
    undir, Oct 1, 2007 IP
  3. lllpumaslll

    lllpumaslll Well-Known Member

    Messages:
    346
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #3
    lllpumaslll, Oct 1, 2007 IP
  4. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Please give an example $friend_id for us to test
     
    undir, Oct 1, 2007 IP
  5. lllpumaslll

    lllpumaslll Well-Known Member

    Messages:
    346
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #5
    Here is an id for example:
    120619749
     
    lllpumaslll, Oct 1, 2007 IP
  6. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
  7. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    is that the image that you are trying to get?
    if yes why the whole script. why dont you just scrape off the image link and download the image?
     
    undir, Oct 1, 2007 IP
  8. lllpumaslll

    lllpumaslll Well-Known Member

    Messages:
    346
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #8
    Yeah, but this is my site pimpmyadds.com
    Enter the id where it says enter id here. Then click enter. Then you should see the default picture on that persons profile. But the picture is not there. Then when you click on view page source, you will see that the image source doesnt match with the picture on that ids profile.
     
    lllpumaslll, Oct 1, 2007 IP
  9. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #9
    do you want me to work on a code for you?
     
    undir, Oct 1, 2007 IP
  10. Ervee

    Ervee Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You are working with the function substr, which takes a part of the string. Making the number longer will create a longer substring.

    What happens if you change this line (almost at the end)
    $name_final = substr($name,23,($len_name-30));
    to
    $name_final = substr($name,23,($len_name-30)+11);

    and when you done that and you get the right url, try
    $name_final = substr($name,23,($len_name-30)+10);

    if it now ends with .jp and not .jpg, it means
    $len_name-30 is wrong, either 30 should be less or $len_name should be 11 longer. Etc...
     
    Ervee, Oct 1, 2007 IP
  11. lllpumaslll

    lllpumaslll Well-Known Member

    Messages:
    346
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #11
    Well, this is what some person that has the same script told me:
    "you will need to edit the path
    alter it so it fits the correct path
    of myspace default picture path"

    I'm assuming all the code needs is to edit some lines.
     
    lllpumaslll, Oct 1, 2007 IP
  12. lllpumaslll

    lllpumaslll Well-Known Member

    Messages:
    346
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    118
    #12
    Tried it and it gives me same source.
     
    lllpumaslll, Oct 1, 2007 IP
  13. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I Fixed this. Customer happy.
     
    undir, Oct 16, 2007 IP
  14. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Are they still happy today? MySpace tweaked their page yet again and the code above won't work.
     
    jnestor, Oct 16, 2007 IP
  15. undir

    undir Peon

    Messages:
    696
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #15
    The above code isn't working anyways. I have written new code for the customer. I wouldn't post it here.
     
    undir, Oct 17, 2007 IP