Jump to content

[SOLVED] Bit of a dilemna


Aureole

Recommended Posts

Long time since I've been here, I've got a little problem.

 

I'm trying to retrieve an image from a certain Website. The image (player model) is generated with an asp script and there are many variables that go into deciding what the image looks like. E.g.:

 

http://www.bungie.net/Stats/Halo3/PlayerModel.ashx?p1=0&p2=8&p3=6&p4=7&p5=7&p6=19&p7=2&p8=10

 

I retrieve a person's player model like so (the function is a lot bigger than this, but I don't need to post it all as this is the only part that retrieves the player model):

 

It isn't in code tags because when I post in code tags the code gets messed up with   type entities...

 

<?php

function fetchHaloStats($gamertag)

{

$player_stats = array();

global $player_stats;

global $error;

 

// Was a Gamertag specified?

if(empty($gamertag))

{

$error = '<p class="content">You didn\'t enter a Gamertag.</p>';

return $error;

}

 

$file = file_get_contents('http://www.bungie.net/Stats/Halo3/Default.aspx?player='.urlencode($gamertag));

 

// Does the Gamertag specified have a Service Record on Bungie.net?

if(preg_match('/Halo 3 Service Record Not Found/i', $file_one))

{

$error = '<p class="content">The Gamertag you entered does not have a Service Record associated with it on Bungie.net.</p>' ;

return $error;

}

 

preg_match('/<img id="ctl00_mainContent_imgModel" src="(.*?)" style="border-width:0px;" \/>/', $file_one, $player_model);

 

$player_stats['Player Model'] = 'http://www.bungie.net'.str_replace('&', '&', $player_model[1]);

 

return $player_stats;

}

?>

 

So if $gametag was "AoR Zayin" (mine) then $file would be "http://www.bungie.net/Stats/Halo3/Default.aspx?player=AoR%20Zayin" and $player_stats['Player Model'] would be "http://www.bungie.net/Stats/Halo3/PlayerModel.ashx?p1=0&p2=8&p3=6&p4=7&p5=7&p6=19&p7=2&p8=10".

 

Now that's all fine and dandy, but if you look at the amount of variables that go into deciding the image... you'll see that I have a problem. I was going to go through every single combination of "p" and save every image on my server, for example:

 

?p1=0&p2=0&p3=0&p4=0&p5=0&p6=0&p7=0&p8=0
?p1=1&p2=1&p3=0&p4=0&p5=0&p6=0&p7=0&p8=0
?p1=0&p2=1&p3=1&p4=0&p5=0&p6=0&p7=0&p8=0
?p1=1&p2=1&p3=1&p4=0&p5=0&p6=0&p7=0&p8=0
etc.

 

But with the sheer amount of values that each "p" can have, that just isn't viable.

 

Now to the point, I want to show a person's player model on their profile, without linking to Bungie's player model script. I need to store all the images on my server (don't worry about copyright, Bungie provide these images for players of their game to use... it's not an issue) but because there are so many combinations I just don't know what to do.

 

The only thing I can think of is when the function finds someone's player model i.e.: "$player_stats['Player Model'] = 'http://www.bungie.net'.str_replace('&', '&', $player_model[1]);" to open that image during the function and save it to my server then.

 

This function is ran once a day 26 times (once for each letter that a user's name begins with) via cron. I split the cron up like that because the script would no doubt time out if it had to do this for every member in one.

 

As the function is running it has a user's id (each user has a unique id) so is there a way I can save that image to my server for each user say for the user with an id of 5, the image would be saved to images/pmodels/5.png for example.

 

That way I DON'T have to hot-link to their image generator script which I really don't want to do as the images will be on my server.

 

Thanks a lot.

Link to comment
Share on other sites

I seem to have resolved the issue...

 

Again not using code tags because your forum's code tags really don't like me.

 

$image = file_get_contents($player_stats['Player Model']);

$new_image = fopen('/path/goes/here/public_html/img/avatars/'.$mem_id.'.jpeg', 'w+'));

fputs($new_image, $image);

fclose($new_image);

unset($image);

 

Sorry if anyone actually had to endure reading all of that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.