PDA

View Full Version : Valuable Addition To image_fix.php


klavixs
02-07-2007, 05:59 PM
ok so yes i've made a very helpful addition to the image_fix.php script.

First:
The problem,
you ever notice that that blueish movie reel image is used for a lot of the thumbs of the movies.But what might not come to mind is did you know each one of the videos uses the same exact image of a real but with different filenames.which in turn means instead of the user downloading 1 real image when viewing your site he gets the same real image over and over again just with different file name. 20kb image x 100(s) is a lot of dling .

solution,
i made an addition to the image_fix.php script which is the last inscrution for each image that takes a control im (basicly the real image named dumb.gif) and checks if its the same as the current thumb.if it is it updates the sql and puts un mThumb "reel.gif" so you only use one image for each reel picture.

enough blabber here it is

make sure the following is in your site

the "/" stands for the main folder of your site for those who dont know

/reel.gif
/images/reel.gif
/image_fix.php
/dumb.gif -just save a copy of that old reel image and name it dumb.gif
thats it.

download all these http://rpgroots.com/updates.zip

The follow is the code with my addtion for those php gurus among us to make any debates or suggestions etc.
anyone not interested or knowledged in php please bypass this
<?php
require("config.php");
$usecurl = "1";
if ($usecurl =='1'){ include("functions/import.curl.php"); }
function file_put_contents2($filename, $data, $flags = 0, $f = FALSE)
{
if(($f === FALSE) && (($flags%2) == 1)) $f = fopen($filename, 'a');
elseif($f === FALSE) $f = fopen($filename, 'w');
if(round($flags/2)==1) while(!flock($f, LOCK_EX)) { /* lock */ }
if(is_array($data)) $data=implode('', $data);
fwrite($f, $data);
if(round($flags/2)==1) flock($f, LOCK_UN); fclose($f);
}

$result2 = mysql_query("SELECT mThumb FROM `media` ORDER BY RAND()") or die(mysql_error());
while (list ($thumb) = mysql_fetch_row($result2)) {
$filename = "images/$thumb";
$filesize = @filesize("images/".$thumb);

if ($filesize ==0) {
if ($usecurl =='1'){ $swfget = ($curl->get('http://www.fastfreemedia.com/images/'.rawurlencode($thumb)));
} else{
$swfget = @file_get_contents('http://www.fastfreemedia.com/images/'.rawurlencode($thumb)); }
if($swfget === false) {
echo '<b>Error:</b> Could not download thumbnail '.$thumb.'<hr />';

if ($usecurl =='1'){ $imgget = ($curl->get("reel.gif")); }else{
$imgget = file_get_contents("reel.gif"); }

file_put_contents2("images/$thumb", $imgget);
} else {
if ($usecurl =='1'){ $imgget = ($curl->get("reel.gif")); } else {
$imgget = file_get_contents("reel.gif"); }

file_put_contents2("images/$thumb", $imgget);
echo "<i>Success:</i> Wrote thumbnail $thumb<hr />";
}
} else {
echo "The file $filename exists<br>";
//new entry By Klavixs
//this is for the reel image is used for many thumbnails but with different filename
//which is a lot of server load for nothing
//this currects it and uses the /reel.gif instead of the thumb
//which is a copy of the same image for hundreds of the videos
//saves webspace too :)

//the control image ( just like science :) )
$cont = fopen("dumb.gif");
//the current thumb
$curThumb = fopen($filename);
//if its another copy
if($cont == $curThumb)
{
//its a duplicate!
echo "Duplicate Reel image detected, correcting...<br />";
//get the mId of the current row cuase you can't "update set image = $image where image = $image"
$s1 = mysql_query("SELECT * FROM media WHERE mThumb = '$thumb'") or die(mysql_error());
//probly a better way then fetch array but f*** it.
$ss1 = mysql_fetch_array($s1);
$Tid = $ss1['mId'];
//now update it use reel.gif instead of duplicate image
$d1 = mysql_query("UPDATE media SET mThumb = 'reel.gif' WHERE mId = '$Tid'") or die(mysql_error());
//if it worked
if(mysql_num_rows($d1) == 1)
{
//say ...
echo "-Duplicate real image updated successfully.-<br />";
}
}
//end of entry by Klavixs :) PEACE

} }
?>


That's it.

Also note to admins: i've been trying to get in the beta for a while now if you would include me i'd be gratefull.

Peace
.:klavixs:.

hiphop
02-11-2007, 01:59 AM
The link is dead for the update files, please re-up.