Page 1 of 1

Myspace Add Train, not showing pictures

Posted: Fri Jun 19, 2009 12:49 pm
by chaospinhead
I have an add train script, it works as far as connecting to the database, and adding people like its supposed to, but none of the profile pictures show up. I don't know PHP enough as to determine why. Can someone help me? This is the code where it pulls the picture.

Code: Select all

 
if ($config['showpics'] == 1) {
$tmpfound = 0;
$file = file("http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=".$row['id']);
foreach ($file as $line) {
 if (strstr($line,"Photo of")) {
  $line = strstr($line,'src=');
  $pattern = "#<img .*?src=[\"']?(.*?)[\"']?(?: .*?>|>)(.*?)</a>#";
  preg_match_all($pattern,$line,$matches);
  echo '<tr><td align="center"><img width=100 height=100 src="'.$matches[1][0].'"></td></tr>';
  $tmpfound = 1;
 }
}
 
All im getting is a red x for the pic and if you view source it says

Code: Select all

<img src="">
where the picture is supposed to show up. So im guessing something wrong with the pattern or preg_match line....but i honestly dont know. It is making it into the If statement though, so its not above that point, it just isnt extracting the photos URL. Any help is appreciated, thanks.

Re: Myspace Add Train, not showing pictures

Posted: Sat Jun 20, 2009 3:33 pm
by Eric!
Can you give us a sample of a string you are trying to parse?

Re: Myspace Add Train, not showing pictures

Posted: Thu Aug 20, 2009 1:55 pm
by TonyScardina
I had rounds with this also... this is the code I ended up using to get it to work...

Code: Select all

 
if ($config['showpics'] == 1) {
$tmpfound = 0;
$file = file("http://www.myspace.com/".$_POST['id']);
foreach ($file as $line) {
if ($tmpfound == 0) {
 if (strstr($line,"images.myspacecdn.com")) {
  $line = strstr($line,'<img ');
  $pattern = "#<img .*?src=[\"']?(.*?)[\"']?(?: .*?>|>)(.*?)#";
  preg_match_all($pattern,$line,$matches);
  $p_image=$matches[1][0];
  $tmpfound = 1;
  unset($file);
 }
}
}
if ($tmpfound == 0) {
  $p_image="nopic.gif";
}
}
 
Be careful though, the method that the script you are using is slow on displaying Images. Its stripping each image out of the list of train riders myspace pages each time the site it viewed. This means that if you have 300 riders on your train it will download 300 different myspace pages, strip out the images for the user, and then display them. I added another field to the 'train' table in the MySQL database that stores the image location 1 time when the user signs up for the train. The script then works significantly faster and then just uses a little more overhead in your MySQL database as opposed to your bandwidth from you host.

If you like I have made some massive changes to this script to make it more functional...
  • Expanded upon the control panel
    Changed the order of the listed riders to mad the newest riders show up at the top
    split the sticky riders out to their own train on the same page
    Add selectable banners at the top and bottom
    modified the train to accept MySpace ID's, MySpace User ID's and Myspace profile URL's
    Changes the train to display riders by a configurable X users wide by Y users Tall instead of just a preset number of riders
    Corrected spelling errors in the scripting and error reporting
...as well as MANY more features being added...


-Tony