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 '<img src="http://www.vgboxart.com'.$matches[0].'"><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 '<img src="myImage.jpg"><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.
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 '<img src="http://www.vgboxart.com'.$matches[0].'"><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 '<img src="myImage.jpg"><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.