phpGD leaves behind a .tmp file every time its executed

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Mon Aug 01, 2005 10:42 pm    Post subject: phpGD leaves behind a .tmp file every time its executed Reply with quote

I'm not sure why but phpGD leaves behind a .tmp file when coding to a .gif file? It only does this with .gif but not .jpg or .png. I would like to use .gif because it is good quality and file size but I'm sick of clearing out .tmp files from the root of my hard drive.

Has anyone got any ideas of how to stop this? Thanks in advance.

The code I use is:

Code:

<?php
/////////////////////////////////////////////////////////
//////////////Abyss web server sig script////////////////
//Contact webmaster@abyssunderground.co.uk for support///
/////////////////////////////////////////////////////////

ini_set("display_errors", 0);

$im = imagecreatefromjpeg("bg.jpg"); // Input Image

$pagefile = "C:\pagefile.sys"; // Your pagefile (for the uptime function)
$multiprocessor = "true"; // Set to true if you have more than one processor/Hyperthreading

$type="wmi"; //Select the type of cpuusage extraction you want to use. (txt for cpuusage.exe or wmi for WMI method)

////////////////////
header("Content-type: image/png");
$uptime = (time() - filemtime($pagefile));
$updays = floor($uptime / (24*3600));
$uptime = $uptime - ($updays * (24*3600));
$uphours = floor($uptime / (3600));
$uptime = $uptime - ($uphours * (3600));
$upminutes = floor($uptime /(60));
$uptime = $uptime - ($upminutes * 60);
$upsecs = $uptime;
$memprog = explode("\n", `memory.exe`);

$totmem = round($memprog[2] /1048576);
$usedmem = round($memprog[3] /1048576);
$freemem = $totmem - $usedmem;

$SLOT0total = round(disk_total_space("h:") /  (1048576),2);
$SLOT0free = round(diskfreespace("h:") /  (1048576),2);
$SLOT0used = $SLOT0total - $SLOT0free;

$line = explode("\n", `netstat -e`);
$line = explode(" ",$line[4]);
$cnt = 0;
for ($i=0;$i<count($line);$i++) {
if ($line[$i]=="") continue;
if ($cnt==0) $text = ucfirst($line[$i]);
elseif ($cnt==1) $rec = $line[$i];
elseif ($cnt==2) $sent = $line[$i];             
$cnt++;
}
$totalrec = round($rec /  (1048576),2);
$totalsend = round($sent  /  (1048576),2);
// Add more here if needed//
$freehd = $drive1free + $drive2free;
$tothd = $drive1total + $drive2total;
$winver = `ver`;
$usrip = $_SERVER['REMOTE_ADDR'];
$usrhost = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$date_time = date("l dS of F Y, h:i:s A");



$message2="% CPU load";
$server="";

if($type=="txt"){
$dataFile = "c:\cpu.txt";
$fp = fopen($dataFile, "r");

        $buffer = fscanf($fp, "%s", $message);
           $cpuDATA=$message;
}


if($type=="wmi"){

if(class_exists("COM")) {
  $wmi = new COM("WinMgmts:\\\\.");
  $cpus = $wmi->InstancesOf("Win32_Processor");
 
  $i = 1;
 
      // Use the while loop on PHP 4 and foreach on PHP 5
  while ($cpu = $cpus->Next()) {
     //foreach ($cpus as $cpu) {
 
   $clockSpeed = $cpu->CurrentClockSpeed;
   $cpuDATA = $cpu->LoadPercentage;
   $i++;
   
  }
}
}

if($cpuDATA>"100") // compensates for cpuusage.exe displaying
$cpuDATA="100";  // 100.5% on a 100% load


//determines the cpu usage message
if($cpuDATA == "0"){
$server="Idle";
}

if($cpuDATA > "0"){
$server="Idle";
}

if($cpuDATA > "10"){
$server="Low use";
}

if($cpuDATA > "30"){
$server="Moderate use";
}

if($cpuDATA > "60"){
$server="High use";
}

if($cpuDATA > "90"){
$server="High stress or under maintainance";
}

if($cpuDATA=="") {
$cpuDATA="??"; 
$server="Unknown. Check WMI or CPUUsage.exe";
}


//reads and writes to the counter file
$fp = fopen("counter.txt", "r");
$count = fread($fp, 1024);
fclose($fp);
$count = $count + 1;
$fp = fopen("counter.txt", "w");
fwrite($fp, $count);
fclose($fp);


//determines the random message
$ran = rand(1,1);

// max letters should not exceed here ---------------------------->|
if($ran=="1"){
$random="This image was created by phpGD. Go to www.php.net for";
$random2="more information about how to use phpGD and phpGD2.";
}

$dynmsg  = "Server Date/Time: ".$date_time."\n";
$dynmsg .= "Server Uptime: ".$updays." days, ".$uphours." hours, ".$upminutes." mins, ".$upsecs." secs\n";
$dynmsg .= "Server Memory: ".$totmem."mb -> Used: ".$freemem."mb, Free: ".$usedmem."mb\n";

$dynmsgcpu .= "Server CPU Usage: ".$cpuDATA."%, (".$server.")\n";

$dynmsg2  = "Network Transfer: -> Sent: ".$totalsend."mb, Received: ".$totalrec."mb\n";
$dynmsg2 .= "Your IP: ".$usrip.", Your DNS: ".$usrhost."\n";

$dynmsgline  = "-------------------------------------------------------------------------------------------------------------";

$dynmsg4 = $random."\n";
$dynmsg42 = $random2."\n";
$dynmsg5 = "Sig Hits: ".$count."     Sig started 31st July 2005";

////////////////////


$txtcolor = imagecolorallocate($im, 0, 0, 0); // Text Color
imagettftext($im, 8, 0, 214, 14, $txtcolor, "../fonts/tahoma.ttf", $dynmsg); //txt-size,slant,left,top


$txtcolor = imagecolorallocate($im, 255, 255, 255); // Text Color
imagettftext($im, 8, 0, 215, 15, $txtcolor, "../fonts/tahoma.ttf", $dynmsg); //txt-size,slant,left,top





$txtcolor = imagecolorallocate($im, 0, 0, 0); // Text Color
imagettftext($im, 8, 0, 214, 58, $txtcolor, "../fonts/tahoma.ttf", $dynmsgcpu); //txt-size,slant,left,top


//determines the cpuusage color
if($cpuDATA == "0"){
$txtcolor = imagecolorallocate($im, 0, 255, 255);
}

if($cpuDATA > "0"){
$txtcolor = imagecolorallocate($im, 0, 255, 255);
}

if($cpuDATA > "10"){
$txtcolor = imagecolorallocate($im, 0, 255, 0);
}

if($cpuDATA > "30"){
$txtcolor = imagecolorallocate($im, 255, 255, 0);
}

if($cpuDATA > "60"){
$txtcolor = imagecolorallocate($im, 255, 155, 0);
}

if($cpuDATA > "90"){
$txtcolor = imagecolorallocate($im, 230, 45, 45);
}

imagettftext($im, 8, 0, 215, 59, $txtcolor, "../fonts/tahoma.ttf", $dynmsgcpu); //txt-size,slant,left,top






$txtcolor = imagecolorallocate($im, 0, 0, 0); // Text Color
imagettftext($im, 8, 0, 214, 72, $txtcolor, "../fonts/tahoma.ttf", $dynmsg2); //txt-size,slant,left,top

$txtcolor = imagecolorallocate($im, 255, 255, 255); // Text Color
imagettftext($im, 8, 0, 215, 73, $txtcolor, "../fonts/tahoma.ttf", $dynmsg2); //txt-size,slant,left,top






$txtcolor = imagecolorallocate($im, 0, 0, 0); // Text Color
imagettftext($im, 8, 0, 214, 96, $txtcolor, "../fonts/tahoma.ttf", $dynmsgline); //txt-size,slant,left,top


$txtcolor = imagecolorallocate($im, 204, 204, 204); // Text Color
imagettftext($im, 8, 0, 215, 97, $txtcolor, "../fonts/tahoma.ttf", $dynmsgline); //txt-size,slant,left,top







$txtcolor = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, 9, 0, 214, 108, $txtcolor, "../fonts/tahoma.ttf", $dynmsg4); //txt-size,slant,left,top


$txtcolor = imagecolorallocate($im, 204, 204, 1);
imagettftext($im, 9, 0, 215, 109, $txtcolor, "../fonts/tahoma.ttf", $dynmsg4); //txt-size,slant,left,top


$txtcolor = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, 9, 0, 215, 122, $txtcolor, "../fonts/tahoma.ttf", $dynmsg42); //txt-size,slant,left,top


$txtcolor = imagecolorallocate($im, 204, 204, 1);
imagettftext($im, 9, 0, 215, 123, $txtcolor, "../fonts/tahoma.ttf", $dynmsg42); //txt-size,slant,left,top






$txtcolor = imagecolorallocate($im, 0, 0, 0); // Text Color
imagettftext($im, 9, 0, 214, 141, $txtcolor, "../fonts/tahoma.ttf", $dynmsg5); //txt-size,slant,left,top


$txtcolor = imagecolorallocate($im, 255, 128, 0); // Text Color
imagettftext($im, 9, 0, 215, 142, $txtcolor, "../fonts/tahoma.ttf", $dynmsg5); //txt-size,slant,left,top





imageinterlace($im,1);
imagegif($im,"",85);
imagedestroy($im);

?>

_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Tim1681
-


Joined: 17 Jan 2005
Posts: 160
Location: Bristol, CT, USA

PostPosted: Tue Aug 02, 2005 12:18 am    Post subject: Reply with quote

Just some stuff i found that may help. It looks like it might be a bug? From what i read, PHP makes the temp file when its making the Image, and I guess the bug happens when PHP tries to Delete the temp file.
http://bugs.php.net/bug.php?id=30348
http://bugs.php.net/bug.php?id=29594&edit=2

And I also found this:
Quote:
iliaa@php.net: This bug has been fixed in CVS.

Hope this helps.
_________________
mysql> SELECT * FROM users WHERE clue > 0;
0 rows returned.

Back to top View user's profile Send private message AIM Address
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Tue Aug 02, 2005 8:45 am    Post subject: Reply with quote

Thanks for those links. I just posted a comment. Seems like it is a bug but isnt even fixed in PHP5 which is unusual. Looks like I will have to stick to .jpeg or .png for now :-(
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group