PDA

View Full Version : Auto-Updating Box Signature Tutorial



Suibuku
01-01-2012, 03:06 PM
Automatic Updating Box Signature Tutorial
I have created this PHP code with some friends help to automatically update your signature with your latest box at the click of a button.


Requirements


A Server
My PHP script



STEP 1

Take this PHP code and paste it into a text document.



<?php

// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.vgboxart.com/author/XXXXXXXXXXX/');

// variable to hold the line number we want to start searching from
$startingLine = "";

// our search term to find the starting line
$regex = '/<div class="headerLarge">Latest Boxes/';

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
if (preg_match($regex, $line)) {
echo "FOUND STARTING POINT: Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
// set the variable to this line number
$startingLine = $line_num;
}
}


$imageRegex = '/(\/.*\.(jpg|png|gif|bmp))/i';

//loop thru the lines again, but this time, starting at out line number and search for the first image
for ($i = $startingLine;$i < count($lines);$i++) {
if (preg_match($imageRegex, $lines[$i], $matches)) {
echo "FOUND: ";
echo "<b>". $matches[0] ."</b><p>";

//show the picture
echo '&lt;img src="http://www.vgboxart.com'.$matches[0].'"&gt;<p>';
echo '<img src="http://www.vgboxart.com'.$matches[0].'">';

//put it on our server
$url = "http://www.vgboxart.com".$matches[0];
$destination=fopen("myImage.jpg","w");
$source=fopen($url,"r");
while ($a=fread($source,1024)) fwrite($destination,$a);
fclose($source);
fclose($destination);

echo '&lt;img src="myImage.jpg"&gt;<p>';
echo '<img src="myImage.jpg">';

// we found our string so stop the loop, we don't need to keep looking
return false;
}
}


?>


STEP 2

Change the "XXXXXXXXXXX" on line 5 to your username.


Step 3

Click on file then click on save as then save it as "vgboxart.php".



Step 4

Upload "vgboxart.php" to your server.



Step 5

After it is uploaded all you have to do it open it up in the web browser, the script will run and the file "myimage.jpg" will be saved onto your server.



Step 6

Go to your settings and then the signature section. Paste this into your signature.

http://xxxxxxxxxxxx/myimage.jpg (http://www.vgboxart.com/author/yyyyyy/)



Step 7

Replace "yyyyyy" with your username. Replace "xxxxxxxxxxxx" with your website.



Step 8

Now, every time you create a new box and upload it all you have to do is open it up in the web browser, the script will run and the file "myimage.jpg" will be re-saved onto your server along with the new boxart.




Credits

The guys over at the phpfreaks.

Spiderpig24
01-01-2012, 08:47 PM
You don't really need a server for something like this though, that's too complicated. Something easy like a free dropbox account would do just fine. Nice job though, pretty cool.

Ronthis the Werewolf
01-03-2012, 12:17 PM
tl;dr

Spiderpig24
01-03-2012, 05:13 PM
tl;dr

Then don't post -_-

Suibuku
01-03-2012, 06:42 PM
tl;dr

Yeah, that really isn't an appropriate comment.

Daemon
01-03-2012, 08:55 PM
tl;dr

Are you trying to be funny? It's not working.

Higashi89
03-16-2012, 06:16 PM
"Too long didn't read"

Ah man, I read the whole thing and was worth it. I'll give a shot anyway, if i'ts not work out (probably because I don't know PHP at all) I'll try the dropbox account because it sounds easier...

EDIT: Ok I'm stuck on the "upload to your server part". What's the server you use?

Spiderpig24
03-16-2012, 06:31 PM
"Too long didn't read"

Ah man, I read the whole thing and was worth it. I'll give a shot anyway, if i'ts not work out (probably because I don't know PHP at all) I'll try the dropbox account because it sounds easier...

EDIT: Ok I'm stuck on the "upload to your server part". What's the server you use?

Instead of using a server, you can use basically any cloud storage service, like DropBox.

Higashi89
03-16-2012, 06:47 PM
Instead of using a server, you can use basically any cloud storage service, like DropBox.
I know, I read your post... but I want to try his method first

Ronthis the Werewolf
03-16-2012, 07:00 PM
tl;dr

Wow, I posted that? o.o

Spiderpig24
03-16-2012, 07:20 PM
I know, I read your post... but I want to try his method first

Well, for the server idea you will need to have a domain and server set up.

Higashi89
03-17-2012, 05:25 AM
Well, for the server idea you will need to have a domain and server set up.
OK, how I do that? #imsonoob

stevencho
03-17-2012, 08:21 AM
OK, how I do that? #imsonoob

Dude seriously. Just use Dropbox.

Higashi89
03-18-2012, 10:59 AM
Dude seriously. Just use Dropbox.
*sigh* fine...

EDIT: I'm stuck in step 5. I tried to open "vgboxart.php" on firefox, but no "myimage" was saved in my dropbox folder...